分析堆棧報(bào)告,例如:
2015-12-28 23:16:39.258 NSLogDemo[1010:65404] -[ViewController func]: unrecognized selector sent to instance 0x7fb2cb517fc0
2015-12-28 23:16:39.262 NSLogDemo[1010:65404] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController func]: unrecognized selector sent to instance 0x7fb2cb517fc0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108201e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000107c78deb objc_exception_throw + 48
2 CoreFoundation 0x000000010820a48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010815790a ___forwarding___ + 970
4 CoreFoundation 0x00000001081574b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001085b1194 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x00000001087206fc -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001087209c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x000000010871faf8 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010862049b -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x00000001086211d0 -[UIWindow sendEvent:] + 865
11 UIKit 0x00000001085cfb66 -[UIApplication sendEvent:] + 263
12 UIKit 0x00000001085a9d97 _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x000000010812da31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010812395c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x0000000108122e13 __CFRunLoopRun + 867
16 CoreFoundation 0x0000000108122828 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x000000010b9faad2 GSEventRunModal + 161
18 UIKit 0x00000001085af610 UIApplicationMain + 171
19 NSLogDemo 0x0000000107777b4f main + 111
20 libdyld.dylib 0x000000010a95592d start + 1
)
第一行代碼的表示 不能識(shí)別ViewController 中的func方法
一條堆棧信息有5部分
19 NSLogDemo 0x0000000107777b4f main + 111
① ② ③ ④ ⑤
第一部分:堆棧輸出序列號(hào)竖慧,序號(hào)越大表示越早被調(diào)用
第二部分:調(diào)用方法(或函數(shù))所屬的框架(或庫(kù))献烦,上面信息中的是我們編寫(xiě)的項(xiàng)目名
第三部分:調(diào)用方法的內(nèi)存地址蒜焊,對(duì)我們用處不大
第四部分:調(diào)用方法(或函數(shù))名旅急,這個(gè)信息很重要
第五部分:調(diào)用方法編譯后的代碼偏移量澎现,不是行號(hào)署辉,沒(méi)什么幫助
堆棧信息是要從下往上看的窍仰,下面的語(yǔ)句是NSLogDemo中的main函數(shù)調(diào)用UIKit中的UIApplicationMain方法
18 UIKit 0x00000001085af610 UIApplicationMain + 171
19 NSLogDemo 0x0000000107777b4f main + 111
最快的閱讀方式是從上向下看短条,找到第二部分中第一個(gè)自己的方法 导匣,找到TA上一行中的第四部分,這個(gè)位置就是出錯(cuò)的地方