prettyprint

2017年6月21日 星期三

[Swift 3] Error: unrecognized selector sent to instance

Problem



self.present(alertController, animated: true, completion: nil)


當 compiling 時,出現下列 error:

2017-06-21 11:04:57.574 HelloWorlDemo[2244:87318] -[HelloWorlDemo.ViewController helloWorldBtn:]: unrecognized selector sent to instance 0x7fc2d2e0f110
2017-06-21 11:04:57.586 HelloWorlDemo[2244:87318] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HelloWorlDemo.ViewController helloWorldBtn:]: unrecognized selector sent to instance 0x7fc2d2e0f110'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010ba65b0b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x0000000108df5141 objc_exception_throw + 48
2   CoreFoundation                      0x000000010bad5134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3   CoreFoundation                      0x000000010b9ec840 ___forwarding___ + 1024
4   CoreFoundation                      0x000000010b9ec3b8 _CF_forwarding_prep_0 + 120
5   UIKit                               0x00000001092c8d82 -[UIApplication sendAction:to:from:forEvent:] + 83
6   UIKit                               0x000000010944d5ac -[UIControl sendAction:to:forEvent:] + 67
7   UIKit                               0x000000010944d8c7 -[UIControl _sendActionsForEvents:withEvent:] + 450
8   UIKit                               0x000000010944c802 -[UIControl touchesEnded:withEvent:] + 618
9   UIKit                               0x00000001093367ea -[UIWindow _sendTouchesForEvent:] + 2707
10  UIKit                               0x0000000109337f00 -[UIWindow sendEvent:] + 4114
11  UIKit                               0x00000001092e4a84 -[UIApplication sendEvent:] + 352
12  UIKit                               0x0000000109ac85d4 __dispatchPreprocessedEventFromEventQueue + 2926
13  UIKit                               0x0000000109ac0532 __handleEventQueue + 1122
14  CoreFoundation                      0x000000010ba0bc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15  CoreFoundation                      0x000000010b9f10cf __CFRunLoopDoSources0 + 527
16  CoreFoundation                      0x000000010b9f05ff __CFRunLoopRun + 911
17  CoreFoundation                      0x000000010b9f0016 CFRunLoopRunSpecific + 406
18  GraphicsServices                    0x000000010d970a24 GSEventRunModal + 62
19  UIKit                               0x00000001092c7134 UIApplicationMain + 159
20  HelloWorlDemo                       0x000000010881d9e7 main + 55
21  libdyld.dylib                       0x000000010ca0565d start + 1
22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb) 

Solution


Swift 3.0 已改版,需將參數 animated 設定值為 false 即可:


self.present(alertController, animated: false, completion: nil)

1 則留言:

  1. Best Hotels Near Harrah's Casino & Spa in Chester, Pennsylvania
    The largest casino-hotel chain in Chester 당진 출장마사지 has a wide range of casino games, 김포 출장안마 Harrah's 포천 출장안마 is 구미 출장샵 Pennsylvania's closest casino to 광주 출장샵 its

    回覆刪除

prettyPrint();