OGeek|极客世界-中国程序员成长平台

标题: objective-c - 为什么没有设置断点时程序会暂停而不崩溃? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 21:03
标题: objective-c - 为什么没有设置断点时程序会暂停而不崩溃?

我有一个项目只是暂停,不会崩溃。它在该集合的最后一行暂停:

 NSLog(@"%@", nibOptions);
 NSLog(@"%@", self.nibName);
 NSLog(@"%@", self.nibBundle);

 [self.nibBundle loadNibNamed:self.nibName owner:self options:nibOptions];

暂停之前的 NSLogs 看起来完全合理。我认为一切都正确连接。但显然有些不对劲。关于解决没有提供信息的暂停的任何建议?没有设置断点。谢谢。 (Xcode 4.2)

编辑:我要补充一点,应用程序位于最前面,然后移到 Xcode 窗口后面。 Nib / View 未加载。

编辑:这是崩溃日志(继续暂停后):

#0  0x90160332 in __kill ()
#1  0x9015f932 in kill$UNIX2003 ()
#2  0x013e136b in CFHash ()
#3  0x01493c04 in __CFDictionaryStandardHashKey ()
#4  0x013e9114 in CFBasicHashFindBucket ()
#5  0x013e8ad5 in CFDictionaryGetValue ()
#6  0x00588ba4 in +[UIProxyObject mappedObjectForCoder:withIdentifier:] ()
#7  0x00588c9d in -[UIProxyObject initWithCoder:] ()
#8  0x00687fa2 in UINibDecoderDecodeObjectForValue ()
#9  0x006876b7 in -[UINibDecoder decodeObjectForKey:] ()
#10 0x00588ead in -[UIRuntimeConnection initWithCoder:] ()
#11 0x00589629 in -[UIRuntimeEventConnection initWithCoder:] ()
#12 0x00687fa2 in UINibDecoderDecodeObjectForValue ()
#13 0x006879af in UINibDecoderDecodeObjectForValue ()
#14 0x006876b7 in -[UINibDecoder decodeObjectForKey:] ()
#15 0x00588305 in -[UINib instantiateWithOwnerptions:] ()
#16 0x0058a010 in -[NSBundle(UINSBundleAdditions) loadNibNamedwnerptions:] ()
#17 0x00002fc5 in -[P3ViewController loadView] at /Users/bryanhanson/Desktop/NastyMarty/P3/Classes/P3ViewController.m:158
#18 0x004305cb in -[UIViewController view] ()
#19 0x00390a73 in -[UIWindow addRootViewControllerViewIfPossible] ()
#20 0x00390ce2 in -[UIWindow _setHidden:forced:] ()
#21 0x00390ea8 in -[UIWindow _orderFrontWithoutMakingKey] ()
#22 0x00397d9a in -[UIWindow makeKeyAndVisible] ()
#23 0x0000297e in -[P3AppDelegate application:didFinishLaunchingWithOptions:] ()
#24 0x003689d6 in -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] ()
#25 0x003698a6 in -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] ()
#26 0x00378743 in -[UIApplication handleEvent:withNewEvent:] ()
#27 0x003791f8 in -[UIApplication sendEvent:] ()
#28 0x0036caa9 in _UIApplicationHandleEvent ()
#29 0x01bc7fa9 in PurpleEventCallback ()
#30 0x014a51c5 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#31 0x0140a022 in __CFRunLoopDoSource1 ()
#32 0x0140890a in __CFRunLoopRun ()
#33 0x01407db4 in CFRunLoopRunSpecific ()
#34 0x01407ccb in CFRunLoopRunInMode ()
#35 0x003692a7 in -[UIApplication _run] ()
#36 0x0036aa9b in UIApplicationMain ()
#37 0x00002458 in main ()



Best Answer-推荐答案


窗口在 Xcode 后面移动,因为它会在您的应用暂停/崩溃时获得焦点。并且 View 不会加载,因为您刚刚调用了 loadnib 或尚未加载(取决于应用暂停的行)。

现在,正如您所说,如果您继续运行您的应用程序会死机,那么这是崩溃而不是暂停。

尝试验证 nib 名称和选项是否正确,以及 xib 文件是否确实存在并与应用程序捆绑在一起。

编辑

尝试接受答案中的解决方案here .

It's crashing in NibDecoder, i.e. when loading your XIB files. You probably have a reference in there to an object or property that doesn't exist or isn't initialized.

以及OP的结论:

I built everything up again from scratch in my custom controller object and i've bypassed what was killing me last time. Every single change I made I compiled and ran in the iPhone sim to make sure I didn't trip myself up. I think my connections to my Controller object must have been incorrect and I was doing something else. So lesson learned is compile and test a lot when doing IB layouts... not just when using Xcode!

所以就试着像他一样:验证 xib 文件中的连接,或者如果可能的话,重新启动它并逐步添加东西以查看导致崩溃的原因。

关于objective-c - 为什么没有设置断点时程序会暂停而不崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9337944/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4