与 insertObject:atIndex 崩溃:对象不能为 nil 但没有数组
Posted
技术标签:
【中文标题】与 insertObject:atIndex 崩溃:对象不能为 nil 但没有数组【英文标题】:crash with insertObject:atIndex: object cannot be nil but no array 【发布时间】:2015-04-22 09:12:13 【问题描述】:我正在与我的应用程序崩溃作斗争,但我找不到它发生的位置。 我正在使用MZFormSheetController 的最新版本。当我收到远程推送时,我展示了一个基本的 MZFormSheetController,它运行良好,但从一天到另一天,它开始崩溃并出现奇怪的堆栈跟踪:
Fatal Exception: NSInvalidArgumentException
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x2bfc2fef __exceptionPreprocess + 126
1 libobjc.A.dylib 0x3a274c8b objc_exception_throw + 38
2 CoreFoundation 0x2bedcefb -[__NSArrayM insertObject:atIndex:] + 638
3 UIKit 0x2fb6289f __workaround10030904InvokeWithTarget_block_invoke + 14
4 UIKit 0x2f8b2ab1 +[UIView _performSystemAppearanceModifications:] + 32
5 UIKit 0x2f780639 workaround10030904InvokeWithTarget + 704
6 UIKit 0x2fb5ff3b applyInvocationsToTarget + 1242
7 UIKit 0x2f6bdd8f +[_UIAppearance _applyInvocationsTo:window:matchingSelector:] + 1262
8 UIKit 0x2f6bd89b +[_UIAppearance _applyInvocationsTo:window:] + 30
9 UIKit 0x2f8bc353 __88-[UIView(Internal) _performUpdatesForPossibleChangesOfIdiom:orScreen:traverseHierarchy:]_block_invoke + 54
10 UIKit 0x2f8bc2cb -[UIView(Internal) _performUpdatesForPossibleChangesOfIdiom:orScreen:traverseHierarchy:] + 262
11 UIKit 0x2f61cf07 -[UIView(Internal) _didChangeFromIdiom:onScreen:traverseHierarchy:] + 30
12 UIKit 0x2f633f0f -[UIScrollView _didChangeFromIdiom:onScreen:traverseHierarchy:] + 46
13 UIKit 0x2f8bc1b7 -[UIView(Internal) _didChangeFromIdiomOnScreen:traverseHierarchy:] + 138
14 UIKit 0x2f61497d -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1316
15 UIKit 0x2f633dfb -[UIScrollView _didMoveFromWindow:toWindow:] + 50
16 UIKit 0x2f6146fb -[UIView(Internal) _didMoveFromWindow:toWindow:] + 674
17 UIKit 0x2f6146fb -[UIView(Internal) _didMoveFromWindow:toWindow:] + 674
18 UIKit 0x2f613fa7 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 114
19 UIKit 0x2f613ec1 -[UIView(Hierarchy) _postMovedFromSuperview:] + 428
20 UIKit 0x2f61e72b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1498
21 UIKit 0x2f61e14b -[UIView(Hierarchy) addSubview:] + 30
22 UIKit 0x2f61db69 -[UIWindow addRootViewControllerViewIfPossible] + 432
23 UIKit 0x2f61b3a1 -[UIWindow _setHidden:forced:] + 272
24 UIKit 0x2f6864a1 -[UIWindow makeKeyAndVisible] + 48
25 Project 0x000f382d -[MZFormSheetController presentAnimated:completionHandler:] (MZFormSheetController.m:509)
26 Project 0x0021b879 __60+[ARDPopupManager showFormsheet:animated:completionHandler:]_block_invoke_2 (ARDPopupManager.m:46)
27 libdispatch.dylib 0x3a7e9ecd _dispatch_barrier_sync_f_slow_invoke + 372
28 libdispatch.dylib 0x3a7df2cf _dispatch_client_callout + 22
29 libdispatch.dylib 0x3a7e2d2f _dispatch_main_queue_callback_4CF + 1330
30 CoreFoundation 0x2bf88609 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
31 CoreFoundation 0x2bf86d09 __CFRunLoopRun + 1512
32 CoreFoundation 0x2bed3201 CFRunLoopRunSpecific + 476
33 CoreFoundation 0x2bed3013 CFRunLoopRunInMode + 106
34 GraphicsServices 0x337b2201 GSEventRunModal + 136
35 UIKit 0x2f677a59 UIApplicationMain + 1440
36 Project 0x0007a88d main (main.m:14)
37 libdyld.dylib 0x3a800aaf start + 2
当然我理解崩溃但是异常断点停在这一行:
[self.formSheetWindow makeKeyAndVisible];
在 MZFormSheetController 库中,MZFormSheetController 是从我的代码中呈现的:
[formsheet presentAnimated:animated completionHandler:nil];
我添加了一个 All Exception Breakpoint,但它没有指向 addObject:
或 insertObject:atIndex:
方法。也许它在其他地方,但我无法弄清楚。我找不到导致此崩溃的 NSArray。
【问题讨论】:
【参考方案1】:终于找到了:在表单控制器中显示的视图控制器中,我添加了一个 UITextView,在我的 AppDelegate 中我写了[[UITextView appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
,当我显示 UITextView 时它崩溃了。所以我不得不在每个 UITextView 实例故事板或代码上单独设置键盘外观...
【讨论】:
令人敬畏的 3 小时调试以愚蠢的问题结束。刚刚评论了两者并解决了问题。 [[UITextView 外观] setKeyboardAppearance:UIKeyboardAppearanceDefault]; [[UITextView 外观] setIndicatorStyle:UIScrollViewIndicatorStyleBlack];【参考方案2】:我认为它会解决问题。
YourViewController *objVc = [[YourViewController alloc] init]; // or you can use initWithNib
// Your remaining code
MZFormSheetController *formSheet = [[MZFormSheetController alloc]initWithViewController:objVc];
formSheet.transitionStyle = MZFormSheetTransitionStyleSlideFromBottom; //try different style
formSheet.presentedFormSheetSize = CGSizeMake(320, self.view.frame.size.height);
formSheet.willPresentCompletionHandler = ^(UIViewController *presentedFSViewController)
presentedFSViewController.view.autoresizingMask = presentedFSViewController.view.autoresizingMask | UIViewAutoresizingFlexibleWidth;
;
formSheet.shouldCenterVertically = YES;
[formSheet presentAnimated:YES completionHandler:^(UIViewController *presentedFSViewController) ];
【讨论】:
以上是关于与 insertObject:atIndex 崩溃:对象不能为 nil 但没有数组的主要内容,如果未能解决你的问题,请参考以下文章
我无法弄清楚这个崩溃:[__NSArrayM insertObject:atIndex:]: object cannot be nil
NSArrayM 中的异常 insertObject:atindex
insertObject: atIndex: - 空数组的索引 3 超出范围
NSArrayM insertObject:atIndex:]: 对象不能为 nil