gpt4 book ai didi

ios - 在第二个 ViewController 文件中调用 @IBAction 函数时崩溃

转载 作者:行者123 更新时间:2023-11-28 08:45:04 24 4
gpt4 key购买 nike

我正在尝试一些关于转场的概念。所以我创建了 secondViewControllerthirdViewController,我还为 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

如何解决?提前致谢

最佳答案

我通过再次检查 thirdViewController 的标识符(发现错误)解决了问题并更正了它。我太粗心了。我认为 unrecognized selector sent to instance 是一个非常重要的线索来找出这个出来。

关于ios - 在第二个 ViewController 文件中调用 @IBAction 函数时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35533155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com