iOS7崩溃 - [__NSPlaceholderDictionary initWithObjects

12

我正在检查我的iOS6应用并尝试为iOS7修复所有问题。在我的应用中,我遇到了以下错误:

-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

这是来自此代码的堆栈跟踪:

NSString *shareString = [NSString stringWithFormat:@"I ... %@", self.booking.venue.name];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]     initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0   CoreFoundation                      0x03bc45e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x032d38b6 objc_exception_throw + 44
2   CoreFoundation                      0x03b8a536 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 390
3   CoreFoundation                      0x03bb8029 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 73
4   UIKit                               0x0141eea4 -[UIButton _intrinsicSizeWithinSize:] + 1255
5   UIKit                               0x017ee81d -[UIView(UIConstraintBasedLayout) intrinsicContentSize] + 51
6   UIKit                               0x017eeebf -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 36
7   UIKit                               0x017eeb50 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 511
8   UIKit                               0x017f4e8f -[UIView(AdditionalLayoutSupport) updateConstraints] + 110
9   UIKit                               0x0141dab7 -[UIButton updateConstraints] + 54
10  UIKit                               0x017f4728 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 239
11  UIKit                               0x017f48a6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
12  UIKit                               0x017f4827 __UIViewRecursionHelper + 40
13  CoreFoundation                      0x03b65dc9 CFArrayApplyFunction + 57
14  UIKit                               0x017f46cc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
15  UIKit                               0x017f48a6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
16  UIKit                               0x017f4827 __UIViewRecursionHelper + 40
17  CoreFoundation                      0x03b65dc9 CFArrayApplyFunction + 57
18  UIKit                               0x017f46cc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
19  UIKit                               0x017f48a6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
20  UIKit                               0x017f4827 __UIViewRecursionHelper + 40
21  CoreFoundation                      0x03b65dc9 CFArrayApplyFunction + 57
22  UIKit                               0x017f46cc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
23  UIKit                               0x017f48a6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
24  UIKit                               0x017f4827 __UIViewRecursionHelper + 40
25  CoreFoundation                      0x03b65dc9 CFArrayApplyFunction + 57
26  UIKit                               0x017f46cc -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 147
27  UIKit                               0x017f48a6 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPass:] + 122
28  UIKit                               0x017e8f48 __62-[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke + 43
29  Foundation                          0x02e7a3ec -[NSISEngine withBehaviors:performModifications:] + 107
30  Foundation                          0x02d0a145 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
31  UIKit                               0x017e8c60 -[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded] + 225
32  UIKit                               0x017f4f06 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtWindowLevelIfNeeded] + 85
33  UIKit                               0x011ed6ef -[UIView(Hierarchy) layoutBelowIfNeeded] + 348
34  UIKit                               0x018a3def -[_UIBackdropContentView backdropView:recursivelyUpdateMaskViewsForView:] + 56
35  UIKit                               0x018a4240 -[_UIBackdropContentView didMoveToWindow] + 273
36  UIKit                               0x011f5be7 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1689
37  UIKit                               0x011f5847 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
38  UIKit                               0x011f5847 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
39  UIKit                               0x011f5847 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
40  UIKit                               0x011f5847 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761
41  UIKit                               0x011ed070 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 162
42  UIKit                               0x011ecef8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 260
43  UIKit                               0x011f8031 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
44  UIKit                               0x011eb521 -[UIView(Hierarchy) addSubview:] + 56
45  UIKit                               0x012861f8 -[UITransitionView transition:fromView:toView:removeFromView:] + 1205
46  UIKit                               0x018add65 -[UIViewControllerBuiltinTransitionViewAnimator animateTransition:] + 463
47  UIKit                               0x0153a37d __101-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:]_block_invoke_2 + 1577
48  UIKit                               0x011acd33 ___afterCACommitHandler_block_invoke + 15
49  UIKit                               0x011accde _applyBlockToCFArrayCopiedToStack + 403
50  UIKit                               0x011acb0a _afterCACommitHandler + 532
51  CoreFoundation                      0x03b8c53e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
52  CoreFoundation                      0x03b8c48f __CFRunLoopDoObservers + 399
53  CoreFoundation                      0x03b6a3b4 __CFRunLoopRun + 1076
54  CoreFoundation                      0x03b69b33 CFRunLoopRunSpecific + 467
55  CoreFoundation                      0x03b6994b CFRunLoopRunInMode + 123
56  GraphicsServices                    0x04fbb9d7 GSEventRunModal + 192
57  GraphicsServices                    0x04fbb7fe GSEventRun + 104
58  UIKit                               0x0119094b UIApplicationMain + 1225
59  BottlesTonight                      0x000030ad main + 141
60  libdyld.dylib                       0x037b8725 start + 0
)


libc++abi.dylib: terminating with uncaught exception of type NSException

这段代码在iOS6上仍然可以完美运行,我没有发现任何问题。它会在点击UIButton时出现,在使用Card.io输入卡片信息时也会出现。在iOS7版本之前构建我的应用程序并在iOS7 beta上运行iOS6应用程序时,我仍然收到此错误,但在更多的地方收到。现在我为iOS7构建了它,有些地方自行清理,但这些地方仍然存在。非常感谢您的任何帮助,这是在提交iOS7之前剩下的所有内容。


堆栈跟踪指向布局 UIButton 的问题。 - rmaddy
我不相信我在其他地方做错了什么。有一个正常的UIButton连接到IBAction。我已经注释掉了那4行代码并放置了日志语句,它工作得非常好,所以它绝对不是按钮的连接方式问题,并且像我说的,在iOS6中这个程序完美地运行。我更倾向于iOS7中存在一个错误。我在这个特定视图上没有使用自动布局,因此堆栈跟踪中的自动布局信息必须来自UIActivityViewController,从而导致崩溃。 - templeman15
1
请检查您的 activityItems 数组是否为空。 - Dinesh Raja
不,它不是nil,而且根据苹果文档,ActivityItems可以为nil。上面的所有四行代码都可以在没有崩溃的情况下运行,在离开我的IBAction方法后它会崩溃。 - templeman15
作为错误信息,您正在尝试使用nil值创建NSDictionary。您需要检查每个数据是否为nil。 - Didats Triadi
显示剩余5条评论
1个回答

1

如果你的布局约束使用正确,那么这是苹果公司代码中的一个错误。请将此报告为Apple的错误:bugreport.apple.com


1
我有同样的错误,而且我甚至没有使用布局约束。 - Laszlo
1
我很久以前就报告了这个问题,但从他们那里没有听到任何回复。真是让人头疼。而且我在这个特定的应用程序中也没有使用自动布局。 - templeman15

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接