https://www.raywenderlich.com/5993-your-first-ios-app/lessons/36
の手順通りに、About the author ボタンとAboutAuthorViewControllerを結びつけて、buildしてAbout the author ボタンを押したら、
libc++abi.dylib: terminating with uncaught exception of type NSException
というエラーが出ました。
助けてください。Controllerのソースは以下です。
ViewController.swift
Swift
1import UIKit 2 3class ViewController: UIViewController { 4 5 var currentValue = 0 6 var targetValue = 0 7 var score = 0 8 var round = 0 9 10 @IBOutlet weak var slider: UISlider! 11 @IBOutlet weak var targetLabel: UILabel! 12 @IBOutlet weak var scoreLabel: UILabel! 13 @IBOutlet weak var roundLabel: UILabel! 14 15 override func viewDidLoad() { 16 super.viewDidLoad() 17 let roundedValue = slider.value.rounded() 18 currentValue = Int(roundedValue) 19 startNewGame() 20 21 let thumbImageNormal = #imageLiteral(resourceName: "SliderThumb-Normal") 22 slider.setThumbImage(thumbImageNormal, for: .normal) 23 24 let thumbImageHighlighted = #imageLiteral(resourceName: "SliderThumb-Highlighted") 25 slider.setThumbImage(thumbImageHighlighted, for: .highlighted) 26 27 let insets = UIEdgeInsets(top:0, left:14, bottom:0, right:14) 28 29 let trackLeftImage = #imageLiteral(resourceName: "SliderTrackLeft") 30 let trackLeftResizable = trackLeftImage.resizableImage(withCapInsets: insets) 31 slider.setMinimumTrackImage(trackLeftResizable, for: .normal) 32 33 let trackRightImage = #imageLiteral(resourceName: "SliderTrackRight") 34 let trackRightResizable = trackRightImage.resizableImage(withCapInsets: insets) 35 slider.setMaximumTrackImage(trackRightResizable, for: .normal) 36 37 } 38 39 @IBAction func showAlert() { 40 41 let difference = abs(targetValue - currentValue) 42 var points = 100 - difference 43 44 score += points 45 46 let title: String 47 if difference == 0 { 48 title = "Perfect!" 49 points += 100 50 } else if difference < 5 { 51 title = "You almost had it!" 52 if difference == 1 { 53 points += 50 54 } 55 } else if difference < 10 { 56 title = "Pretty good!" 57 } else { 58 title = "Not even close..." 59 } 60 61 let message = "You scored (points) points" 62 63 let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) 64 65 let action = UIAlertAction(title: "OK", style: .default, handler: { 66 action in 67 self.startNewRound() 68 }) 69 70 alert.addAction(action) 71 72 present(alert, animated: true, completion: nil) 73 74 } 75 76 @IBAction func sliderMoved(_ slider: UISlider) { 77 let roundedValue = slider.value.rounded() 78 currentValue = Int(roundedValue) 79 } 80 81 func startNewRound() { 82 round += 1 83 targetValue = Int.random(in: 1...100) 84 currentValue = 50 85 slider.value = Float(currentValue) 86 updateLabels() 87 } 88 89 func updateLabels() { 90 targetLabel.text = String(targetValue) 91 scoreLabel.text = String(score) 92 roundLabel.text = String(round) 93 } 94 95 @IBAction func startNewGame() { 96 score = 0 97 round = 0 98 startNewRound() 99 } 100 101} 102
AboutAuthorViewController.swift
Swift
1import UIKit 2 3class AboutAuthorViewController: UITableViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 } 8 9 @IBAction func close() { 10 dismiss(animated: true, completion: nil) 11 } 12 13}
AboutViewController.swift
Swift
1import UIKit 2import WebKit 3 4class AboutViewController: UIViewController { 5 6 @IBOutlet weak var webView: WKWebView! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 if let htmlPath = Bundle.main.path(forResource: "BullsEye", ofType: "html"){ 11 let url = URL(fileURLWithPath: htmlPath) 12 let request = URLRequest(url: url) 13 webView.load(request) 14 } 15 } 16 17 @IBAction func close() { 18 dismiss(animated: true, completion: nil) 19 } 20 21}
Main.storyboardのスクショは以下です。
ソースコード下部に表示されているエラーをすべて追記してください
2019-08-23 15:54:56.729262+0900 BullsEye[2303:2518499] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-txn-hs-ABh" from storyboard "Main", but didn't get a UITableView.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107c008db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x00000001061b8ac5 objc_exception_throw + 48
2 CoreFoundation 0x0000000107c00735 +[NSException raise:format:] + 197
3 UIKitCore 0x0000000109e8c827 -[UITableViewController loadView] + 621
4 UIKitCore 0x0000000109e9bd04 -[UIViewController loadViewIfRequired] + 172
5 UIKitCore 0x0000000109e9c524 -[UIViewController view] + 27
6 UIKitCore 0x0000000109dc35b4 -[_UIFullscreenPresentationController _setPresentedViewController:] + 89
7 UIKitCore 0x0000000109db76aa -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133
8 UIKitCore 0x0000000109eaf18a -[UIViewController _presentViewController:withAnimationController:completion:] + 3700
9 UIKitCore 0x0000000109eb1dd7 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
10 UIKitCore 0x0000000109eb22ef -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
11 UIKitCore 0x0000000109eb1d3e -[UIViewController _presentViewController:animated:completion:] + 172
12 UIKitCore 0x0000000109eb1f9c -[UIViewController presentViewController:animated:completion:] + 150
13 UIKitCore 0x000000010a6367e2 __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133
14 UIKitCore 0x000000010a63b4d3 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 276
15 UIKitCore 0x000000010a63b391 -[UIStoryboardSegueTemplate _perform:] + 82
16 UIKitCore 0x000000010a63b653 -[UIStoryboardSegueTemplate perform:] + 157
17 UIKitCore 0x000000010a4a0624 -[UIApplication sendAction:to:from:forEvent:] + 83
18 UIKitCore 0x0000000109ef58d5 -[UIControl sendAction:to:forEvent:] + 67
19 UIKitCore 0x0000000109ef5bf2 -[UIControl _sendActionsForEvents:withEvent:] + 450
20 UIKitCore 0x0000000109ef4ba8 -[UIControl touchesEnded:withEvent:] + 583
21 UIKitCore 0x000000010a4d94e6 -[UIWindow _sendTouchesForEvent:] + 2547
22 UIKitCore 0x000000010a4dabca -[UIWindow sendEvent:] + 4079
23 UIKitCore 0x000000010a4b930e -[UIApplication sendEvent:] + 356
24 UIKitCore 0x000000010a5892b3 __dispatchPreprocessedEventFromEventQueue + 3232
25 UIKitCore 0x000000010a58bbd9 __handleEventQueueInternal + 5911
26 CoreFoundation 0x0000000107b67db1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
27 CoreFoundation 0x0000000107b67633 __CFRunLoopDoSources0 + 243
28 CoreFoundation 0x0000000107b61cef __CFRunLoopRun + 1231
29 CoreFoundation 0x0000000107b614d2 CFRunLoopRunSpecific + 626
30 GraphicsServices 0x000000010fccc2fe GSEventRunModal + 65
31 UIKitCore 0x000000010a49efc2 UIApplicationMain + 140
32 BullsEye 0x00000001058d08cb main + 75
33 libdyld.dylib 0x000000010900d541 start + 1
34 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
です!
質問を編集し、storyboardのスクリーンショットと
viewcontrollerのコードを全部追記していただけると、
答えがつくと思います。
編集しました!
回答1件
あなたの回答
tips
プレビュー