2016-06-28 36 views
1

我得到这个错误,我不知道为什么? 我已经开始今天的学习迅速class AppDelegate:UIResponder,UIApplicationDelegate {SIGIFT错误在SWIFT

2016-06-28 02:40:03.393 Calculator[7072:173608] -[Calculator.ViewController touchDigit]: unrecognized selector sent to instance 0x7fc4a9465000 
2016-06-28 02:40:03.400 Calculator[7072:173608] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Calculator.ViewController touchDigit]: unrecognized selector sent to instance 0x7fc4a9465000' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0000000100c40e65 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x0000000102980deb objc_exception_throw + 48 
    2 CoreFoundation      0x0000000100c4948d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x0000000100b9690a ___forwarding___ + 970 
    4 CoreFoundation      0x0000000100b964b8 _CF_forwarding_prep_0 + 120 
    5 UIKit        0x000000010145f194 -[UIApplication sendAction:to:from:forEvent:] + 92 
    6 UIKit        0x00000001015ce6fc -[UIControl sendAction:to:forEvent:] + 67 
    7 UIKit        0x00000001015ce9c8 -[UIControl _sendActionsForEvents:withEvent:] + 311 
    8 UIKit        0x00000001015cdaf8 -[UIControl touchesEnded:withEvent:] + 601 
    9 UIKit        0x00000001014ce49b -[UIWindow _sendTouchesForEvent:] + 835 
    10 UIKit        0x00000001014cf1d0 -[UIWindow sendEvent:] + 865 
    11 UIKit        0x000000010147db66 -[UIApplication sendEvent:] + 263 
    12 UIKit        0x0000000101457d97 _UIApplicationHandleEventQueue + 6844 
    13 CoreFoundation      0x0000000100b6ca31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    14 CoreFoundation      0x0000000100b6295c __CFRunLoopDoSources0 + 556 
    15 CoreFoundation      0x0000000100b61e13 __CFRunLoopRun + 867 
    16 CoreFoundation      0x0000000100b61828 CFRunLoopRunSpecific + 488 
    17 GraphicsServices     0x0000000105256ad2 GSEventRunModal + 161 
    18 UIKit        0x000000010145d610 UIApplicationMain + 171 
    19 Calculator       0x0000000100a6361d main + 109 
    20 libdyld.dylib      0x000000010348992d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

我的主要类只有这个简单的方法,不知道发生了什么

import UIKit 

internal class ViewController : UIViewController { 

    @IBAction internal func touchDigit(sender: UIButton) 
} 

谢谢

+3

发布问题时,请仔细考虑一下。您只需剪切并粘贴代码,并使用零格式或查看标点符号等等。touchDigit方法中有什么? – Adrian

回答

2

尝试解除绑定你的行动,你的情节提要/ XIB ,然后重新绑定它。

我猜测基于错误缺少:(应该是[ViewController touchDigit:],因为有一种说法),您将添加的参数sender后您的故事板设置它。

我刚刚测试过这个,重新绑定它后,故事版显示它为touchDigitWithSender,即使它保留名称touchDigit。可能是一些奇怪的Swift/Objective-C互操作性的东西。


P.S. internal是默认访问说明符,您不必将其添加到每个声明中

+0

非常有用的答案 - 我刚刚更新了我的项目Swift 3,并一直在想,为什么第一个按钮现在崩溃应用程序。这固定了它。 – dumbledad