Swift:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:无法识别的选择器发送到实例 0x7fb179f12260'

Posted

技术标签:

【中文标题】Swift:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:无法识别的选择器发送到实例 0x7fb179f12260\'【英文标题】:Swift : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason : unrecognized selector sent to instance 0x7fb179f12260'Swift:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:无法识别的选择器发送到实例 0x7fb179f12260' 【发布时间】:2016-05-23 10:27:26 【问题描述】:

我正在开发一个简单的应用程序,但这个问题困扰了我很长时间!

我尝试使用 segue 传输模型!

上面的一个函数是UITextField作为Action,但是当我用它打开时。崩溃!

另一个可以打开模型。不会崩溃!

class showVerifyViewController: UIViewController 


    @IBOutlet weak var verifyText: UITextField!

    @IBAction func setNewPinText(sender: AnyObject) 
        if verifyText.text == "zzz" 
            let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SetupPinViewController") as UIViewController
            let navigationView  = UINavigationController(rootViewController: viewController)
            self.presentViewController(navigationView, animated: true, completion: nil)
        
    

    @IBAction func showTest(sender: AnyObject) 
        let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SetupPinViewController") as UIViewController
        let navigationView  = UINavigationController(rootViewController: viewController)
        self.presentViewController(navigationView, animated: true, completion: nil)
    


[SoftPin.showVerifyViewController setNewPintext:]: unrecognized selector sent to instance 0x7fb179f12260
2016-05-23 18:19:58.372 SoftPin[2805:268743] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SoftPin.showVerifyViewController setNewPintext:]: unrecognized selector sent to instance 0x7fb179f12260'

0   CoreFoundation                      0x00000001051c8d85 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000106f6cdeb objc_exception_throw + 48
2   CoreFoundation                      0x00000001051d1d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x0000000105117cfa ___forwarding___ + 970
4   CoreFoundation                      0x00000001051178a8 _CF_forwarding_prep_0 + 120
5   UIKit                               0x00000001059f2a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6   UIKit                               0x0000000105b65e67 -[UIControl sendAction:to:forEvent:] + 67
7   UIKit                               0x0000000105b66143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8   UIKit                               0x00000001063ef6c5 -[UITextField _resignFirstResponder] + 298
9   UIKit                               0x0000000105c04a1a -[UIResponder _finishResignFirstResponder] + 292
10  UIKit                               0x00000001063ef4ef -[UITextField _finishResignFirstResponder] + 49
11  UIKit                               0x0000000105c04ac9 -[UIResponder resignFirstResponder] + 140
12  UIKit                               0x00000001063ef3bc -[UITextField resignFirstResponder] + 136
13  UIKit                               0x0000000105a97afd -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 161
14  UIKit                               0x0000000105a9802a __UIViewWillBeRemovedFromSuperview + 71
15  UIKit                               0x0000000105a97e48 -[UIView(Hierarchy) removeFromSuperview] + 99
16  UIKit                               0x0000000105b61afb __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke596 + 739
17  UIKit                               0x0000000105b5bdbe -[UIPresentationController transitionDidFinish:] + 111
18  UIKit                               0x0000000105d3938f -[_UICurrentContextPresentationController transitionDidFinish:] + 42
19  UIKit                               0x0000000105b5f7c1 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
20  UIKit                               0x000000010641e4c8 -[_UIViewControllerTransitionContext completeTransition:] + 101
21  UIKit                               0x0000000105b58f77 -[UITransitionView notifyDidCompleteTransition:] + 252
22  UIKit                               0x0000000105b58c88 -[UITransitionView _didCompleteTransition:] + 1344
23  UIKit                               0x0000000105b5b3f4 -[UITransitionView _transitionDidStop:finished:] + 104
24  UIKit                               0x0000000105a7e7ff -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
25  UIKit                               0x0000000105a7ebae -[UIViewAnimationState animationDidStop:finished:] + 80
26  QuartzCore                          0x000000010a4723c8 _ZN2CA5Layer23run_animation_callbacksEPv + 308
27  libdispatch.dylib                   0x00000001079fc3eb _dispatch_client_callout + 8
28  libdispatch.dylib                   0x00000001079e41ef _dispatch_main_queue_callback_4CF + 1738
29  CoreFoundation                      0x00000001051220f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
30  CoreFoundation                      0x00000001050e3b99 __CFRunLoopRun + 2073
31  CoreFoundation                      0x00000001050e30f8 CFRunLoopRunSpecific + 488
32  GraphicsServices                    0x000000010985ead2 GSEventRunModal + 161
33  UIKit                               0x00000001059f0f09 UIApplicationMain + 171
34  SoftPin                             0x0000000104fcacd2 main + 114
35  libdyld.dylib                       0x0000000107a3092d start + 1
36  ???                                 0x0000000000000001 0x0 + 1
)

    libc++abi.dylib: terminating with uncaught exception of type NSException

真的需要一些建议!

【问题讨论】:

感谢您的建议! showVerifyViewController 中没有名为“setNewPintext”的函数。 @Eiko 无论格式正确,您的编辑都使堆栈跟踪不可读 @TimCastelijns 同意。 :) 没想到它有那么大的影响——它正在改进建议的编辑——但不记得我在这里究竟做了什么。下次会更彻底地检查。 【参考方案1】:

错误告诉你在SoftPin.showVerifyViewController 上调用setNewPintext:,但该方法不存在。也许是错字?也许应该是setNewPinText(带有大写的T)?:

【讨论】:

不太明白你的回答。我设置了一个名为 verifyText 的插座和一个名为 setNewPinText 的函数。为什么该方法不存在? 您使用与定义方式不同的名称调用该方法。它似乎被称为setNewPintext(如SoftPin.showVerifyViewController.setNewPintext("something"),带有小写的t)。但正如您在更新中看到的那样,它被定义为setNewPinText(带有大写T

以上是关于Swift:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:无法识别的选择器发送到实例 0x7fb179f12260'的主要内容,如果未能解决你的问题,请参考以下文章

Swift 项目以 NSException 类型的未捕获异常终止

iOS未捕获的异常添加子视图崩溃

由于未捕获的异常“RLMException”而终止应用程序,原因:“索引 0 超出范围(必须小于 0)。”迅速

swift - 如何处理未捕获的异常

Swift:应用程序因未捕获的异常“NSUnknownKeyException”而终止

UIRefreshControl 在下拉时崩溃 - 未捕获的异常 Swift