使用insertObject崩溃:atIndex:对象不能为nil但不能为数组

时间:2015-04-22 09:12:14

标签: ios objective-c nsarray null

我正在与我的应用程序中的崩溃作斗争,但我无法找到它发生的位置。 我正在使用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。

2 个答案:

答案 0 :(得分:3)

终于找到了:在表单控制器中显示的视图控制器中,我添加了一个UITextView,在我的AppDelegate中我编写了[[UITextView appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];,当我呈现UITextView时它崩溃了。所以我必须在每个UITextView实例故事板或代码上单独设置键盘外观......

答案 1 :(得分:0)

我认为它会解决问题。

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){ }];