在研究 Objective-C 时,它的高度动态性的后果之一是,即使它在运行时不会响应它,也可以向对象发送任何消息。
然后它将忽略该消息并引发异常。
在一个实际情况下,我试图向一个委托对象发送一条消息,该对象在委托中没有实现。
当然,我必须实现它才能拥有我的功能,但纯粹出于兴趣,我想知道为什么我的应用程序在我不这样做时会崩溃。
2011-06-05 17:44:39.280 myTest[28158:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TVC DoneLoadingNoStoriesFound:]: unrecognized selector sent to instance 0x5c0ef90'
*** Call stack at first throw:
(
0 CoreFoundation 0x015cabe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0171f5c2 objc_exception_throw + 47
2 CoreFoundation 0x015cc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0153c366 ___forwarding___ + 966
4 CoreFoundation 0x0153bf22 _CF_forwarding_prep_0 + 50
5 myTest 0x0003db93 -[Loader loadTasksForStoriesForDisplayedWorkpace] + 1268
6 myTest 0x0003d388 -[Loader requestFinished:] + 1936
7 myTest 0x00017f2e -[ASIHTTPRequest reportFinished] + 100
8 Foundation 0x001f69a6 __NSThreadPerformPerform + 251
9 CoreFoundation 0x015ac01f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
10 CoreFoundation 0x0150a28b __CFRunLoopDoSources0 + 571
11 CoreFoundation 0x01509786 __CFRunLoopRun + 470
12 CoreFoundation 0x01509240 CFRunLoopRunSpecific + 208
13 CoreFoundation 0x01509161 CFRunLoopRunInMode + 97
14 GraphicsServices 0x01b0f268 GSEventRunModal + 217
15 GraphicsServices 0x01b0f32d GSEventRun + 115
16 UIKit 0x0048642e UIApplicationMain + 1160
17 myTest 0x0000272b main + 85
18 myTest 0x000026cd start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
kill
quit