我正在尝试一些关于segues的概念。所以我创建了secondViewController
和thirdViewController
,我还为secondViewController
创建了一个ViewController文件。然后我在secondViewController
上添加了一个按钮,并将一些代码添加到secondViewController.swift
。这是代码,非常简单:
import UIKit
class secondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func onNext(sender: AnyObject) {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("thirdViewController")
showViewController(vc, sender: self)
}
}
在构建和运行之后,当我点击“下一步”按钮时,它就崩溃了。
2016-02-21 14:28:24.244 test[4176:476944] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController onNext:]: unrecognized selector sent to instance 0x7fea72c48e20'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f795e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001114d5deb objc_exception_throw + 48
2 CoreFoundation 0x000000010f79e48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f6eb90a ___forwarding___ + 970
4 CoreFoundation 0x000000010f6eb4b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010ffb4194 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x00000001101236fc -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001101239c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x0000000110122af8 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000011002349b -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x00000001100241d0 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010ffd2b66 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010ffacd97 _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x000000010f6c1a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010f6b795c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010f6b6e13 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010f6b6828 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000113dabad2 GSEventRunModal + 161
18 UIKit 0x000000010ffb2610 UIApplicationMain + 171
19 test 0x000000010f5b750d main + 109
20 libdyld.dylib 0x0000000111fde92d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
如何解决?提前致谢
答案 0 :(得分:0)
我通过再次检查thirdViewController的标识符来解决问题(错误地说明了它)并更正了它。我太粗心了。我认为unrecognized selector sent to instance
是解决这个问题的一个非常重要的线索。