我记得使用编译器(我认为JCreator或Eclipse)会告诉你它崩溃的代码行。我在XCode中找不到这个信息。它有这个功能吗?
编辑:
这是一个示例堆栈抛出
2011-02-26 18:07:24.859 NumbersFlashCards[8803:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString size]: unrecognized selector sent to instance 0x531b580'
* 首次调用堆栈:
(
0 CoreFoundation 0x00ebabe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0100f5c2 objc_exception_throw + 47
2 CoreFoundation 0x00ebc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00e2c366 ___forwarding___ + 966
4 CoreFoundation 0x00e2bf22 _CF_forwarding_prep_0 + 50
5 UIKit 0x0039ab68 -[UIImageView initWithImage:] + 51
6 NumbersFlashCards 0x00003373 -[LettersFlashCardsViewController viewDidLoad] + 3311
7 UIKit 0x0037d65e -[UIViewController view] + 179
8 UIKit 0x0037f012 -[UIViewController viewControllerForRotation] + 63
9 UIKit 0x0037af76 -[UIViewController _visibleView] + 90
10 UIKit 0x00614a97 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 354
11 UIKit 0x002f6ba8 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 954
12 UIKit 0x00576948 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1053
13 UIKit 0x00381982 -[UIViewController presentModalViewController:withTransition:] + 3151
14 NumbersFlashCards 0x00005d83 -[StartPage start] + 103
15 UIKit 0x002cfa6e -[UIApplication sendAction:to:from:forEvent:] + 119
16 UIKit 0x0035e1b5 -[UIControl sendAction:to:forEvent:] + 67
17 UIKit 0x00360647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
18 UIKit 0x0035f438 -[UIControl touchesBegan:withEvent:] + 277
19 UIKit 0x002f4025 -[UIWindow _sendTouchesForEvent:] + 395
20 UIKit 0x002d537a -[UIApplication sendEvent:] + 447
21 UIKit 0x002da732 _UIApplicationHandleEvent + 7576
22 GraphicsServices 0x017f0a36 PurpleEventCallback + 1550
23 CoreFoundation 0x00e9c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
24 CoreFoundation 0x00dfc6f7 __CFRunLoopDoSource1 + 215
25 CoreFoundation 0x00df9983 __CFRunLoopRun + 979
26 CoreFoundation 0x00df9240 CFRunLoopRunSpecific + 208
27 CoreFoundation 0x00df9161 CFRunLoopRunInMode + 97
28 GraphicsServices 0x017ef268 GSEventRunModal + 217
29 GraphicsServices 0x017ef32d GSEventRun + 115
30 UIKit 0x002de42e UIApplicationMain + 1160
31 NumbersFlashCards 0x00002320 main + 102
32 NumbersFlashCards 0x000022b1 start + 53
33 ??? 0x00000001 0x0 + 1
)
我知道崩溃是在我的代码的第112行引起的(我用nslogs包围它以缩小它的范围)。但我在这里看不到112?我只是不想每次都使用nslog来跟踪它。
答案 0 :(得分:1)
Xcode使用GNU Debugger GDB。在(gdb)提示符下键入'where'或'backtrace'或'bt',您将看到回溯。这会显示导致崩溃的调用堆栈。您将在回溯中看到文件路径和行号。有时这直接指向罪魁祸首。
terminate called after throwing an instance of 'NSException'
(gdb) where
#0 0x3105ba1c in __pthread_kill ()
#1 0x34e0a3ba in pthread_kill ()
#2 0x34e02bfe in abort ()
#3 0x32c29a6a in __gnu_cxx::__verbose_terminate_handler ()
#4 0x35d66072 in _objc_terminate ()
#5 0x32c27e3c in __cxxabiv1::__terminate ()
#6 0x32c27e90 in std::terminate ()
#7 0x32c27f60 in __cxa_throw ()
#8 0x35d64c8a in objc_exception_throw ()
#9 0x34d8f3cc in -[NSException raise] ()
#10 0x3159ceda in -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] ()
#11 0x315559ca in _NSSetUsingKeyValueSetter ()
#12 0x31555216 in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
#13 0x3153742e in -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] ()
#14 0x3568c8de in -[UIRuntimeOutletConnection connect] ()
#15 0x34d27d7a in -[NSObject(NSObject) performSelector:] ()
#16 0x34d2799c in -[NSArray makeObjectsPerformSelector:] ()
#17 0x3568b846 in -[UINib instantiateWithOwner:options:] ()
#18 0x3568ce08 in -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] ()
#19 0x354b74cc in -[UIApplication _loadMainNibFile] ()
#20 0x354b1b08 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
#21 0x354867d6 in -[UIApplication handleEvent:withNewEvent:] ()
#22 0x35486214 in -[UIApplication sendEvent:] ()
#23 0x35485c52 in _UIApplicationHandleEvent ()
#24 0x32199e76 in PurpleEventCallback ()
#25 0x34d66a96 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#26 0x34d6883e in __CFRunLoopDoSource1 ()
#27 0x34d6960c in __CFRunLoopRun ()
#28 0x34cf9ec2 in CFRunLoopRunSpecific ()
#29 0x34cf9dca in CFRunLoopRunInMode ()
#30 0x354b0d48 in -[UIApplication _run] ()
#31 0x354ae806 in UIApplicationMain ()
#32 0x00002ce2 in main (argc=1, argv=0x2fdff544) at /Users/dogbert/Documents/myNoobProject/main.m:13
答案 1 :(得分:0)
您在Xcode中使用“运行和调试”。如果崩溃,则调用堆栈位于调试器窗口的左上角。单击顶部项目以查看崩溃的位置。单击任何其他行以查看该呼叫。