终止与NSException类型的未捕获异常 - Xcode

时间:2015-07-02 02:47:30

标签: ios swift unrecognized-selector nsexception

我正在使用Xcode 6.4并在尝试使用后退按钮时出现以下错误我硬编码:

2015-07-01 22:41:47.082 oby[14979:280903] -[oby.PhotoViewController popView]: unrecognized selector sent to instance 0x7f8112f24d90
2015-07-01 22:41:47.103 oby[14979:280903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[oby.PhotoViewController popView]: unrecognized selector sent to instance 0x7f8112f24d90'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105b92c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001076fdbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000105b9a0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000105af013c ___forwarding___ + 988
    4   CoreFoundation                      0x0000000105aefcd8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000106432d62 -[UIApplication sendAction:to:from:forEvent:] + 75
    6   UIKit                               0x000000010654450a -[UIControl _sendActionsForEvents:withEvent:] + 467
    7   UIKit                               0x00000001065438d9 -[UIControl touchesEnded:withEvent:] + 522
    8   UIKit                               0x000000010647f958 -[UIWindow _sendTouchesForEvent:] + 735
    9   UIKit                               0x0000000106480282 -[UIWindow sendEvent:] + 682
    10  UIKit                               0x0000000106446541 -[UIApplication sendEvent:] + 246
    11  UIKit                               0x0000000106453cdc _UIApplicationHandleEventFromQueueEvent + 18265
    12  UIKit                               0x000000010642e59c _UIApplicationHandleEventQueue + 2066
    13  CoreFoundation                      0x0000000105ac6431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x0000000105abc2fd __CFRunLoopDoSources0 + 269
    15  CoreFoundation                      0x0000000105abb934 __CFRunLoopRun + 868
    16  CoreFoundation                      0x0000000105abb366 CFRunLoopRunSpecific + 470
    17  GraphicsServices                    0x000000010a676a3e GSEventRunModal + 161
    18  UIKit                               0x00000001064318c0 UIApplicationMain + 1282
    19  oby                                 0x00000001053502b7 main + 135
    20  libdyld.dylib                       0x0000000107e33145 start + 1
    21  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

按钮:

let btn = UINavButton(title: "Back", direction: UIButtonDirection.Left, parentView: self.view)
btn.addTarget(self, action: "popView", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)

有人可以帮我解决这个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

像这样的东西

btn.addTarget(self, action: "backAction", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)

func backAction() {
    self.navigationController?.popViewControllerAnimated(true)
}