在UITableView中_updateNumSections上导致SIGSEGV的原因是什么?

时间:2011-10-01 06:38:58

标签: iphone objective-c crash

我们偶尔会得到以下内容。我们无法重新创建此错误。

有谁知道具体原因是什么?看起来UITableView处于一些奇怪的状态。我已经运行了仪器寻找过度释放的内存等,但我看不到多少。

Thread 0 Crashed:
    libobjc.A.dylib                     0x3068f06b _objc_terminate + 103
    libstdc++.6.dylib                   0x30502e3d __cxxabiv1::__terminate(void (*)()) + 53
    libstdc++.6.dylib                   0x30502e91 std::terminate() + 17
    libstdc++.6.dylib                   0x30502f61 __cxa_throw + 85
    libobjc.A.dylib                     0x3068dc8b objc_exception_throw + 71
    CoreFoundation                      0x335141bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 103
    CoreFoundation                      0x33513649 ___forwarding___ + 509
    CoreFoundation                      0x3348a180 _CF_forwarding_prep_0 + 48
    UIKit                               0x31bb2ff3 -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 67
    UIKit                               0x31bb2f53 -[UITableViewRowData invalidateAllSections] + 51
    UIKit                               0x31bb2d09 -[UITableView(_UITableViewPrivate) _updateRowData] + 65
    UIKit                               0x31bafab7 -[UITableView _rectChangedWithNewSize:oldSize:] + 111
    UIKit                               0x31bae833 -[UITableView setFrame:] + 159
    UIKit                               0x31bb5e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 275
    UIKit                               0x31b820bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 121
    UIKit                               0x31b674e9 -[UIView(Geometry) setFrame:] + 337
    UIKit                               0x31bb5e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 275
    UIKit                               0x31b820bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 121
    UIKit                               0x31b674e9 -[UIView(Geometry) setFrame:] + 337
    UIKit                               0x31bae9fd -[UIScrollView setFrame:] + 421
    UIKit                               0x31bb5e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 275
    UIKit                               0x31b820bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 121
    UIKit                               0x31b674e9 -[UIView(Geometry) setFrame:] + 337
    UIKit                               0x31bb5e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 275
    UIKit                               0x31b820bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 121
    UIKit                               0x31b674e9 -[UIView(Geometry) setFrame:] + 337
    UIKit                               0x31bb9193 -[UIViewControllerWrapperView setFrame:] + 63
    UIKit                               0x31bb5e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 275
    UIKit                               0x31b820bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 121
    UIKit                               0x31b674e9 -[UIView(Geometry) setFrame:] + 337
    UIKit                               0x31bb5e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 275
    UIKit                               0x31b820bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 121
    UIKit                               0x31b674e9 -[UIView(Geometry) setFrame:] + 337
    UIKit                               0x31b9922f -[UILayoutContainerView setFrame:] + 55
    UIKit                               0x31bb90a9 +[UIViewControllerWrapperView wrapperViewForView:frame:] + 225
    UIKit                               0x31bd6201 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 105
    UIKit                               0x31bd618d -[UITabBarController transitionFromViewController:toViewController:] + 33
    UIKit                               0x31bd5a33 -[UITabBarController _setSelectedViewController:] + 187
    UIKit                               0x31c5aceb -[UITabBarController setSelectedViewController:] + 15
    UIKit                               0x31c5abe7 -[UITabBarController _tabBarItemClicked:] + 227
    CoreFoundation                      0x33480571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 25
    UIKit                               0x31b7eec9 -[UIApplication sendAction:to:from:forEvent:] + 85
    UIKit                               0x31b7ee69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 33
    UIKit                               0x31c5aa8b -[UITabBar _sendAction:withEvent:] + 271
    CoreFoundation                      0x33480571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 25
    UIKit                               0x31b7eec9 -[UIApplication sendAction:to:from:forEvent:] + 85
    UIKit                               0x31b7ee69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 33
    UIKit                               0x31b7ee3b -[UIControl sendAction:to:forEvent:] + 39
    UIKit                               0x31b7eb8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 357
    UIKit                               0x31bb8bd9 -[UIControl sendActionsForControlEvents:] + 17
    UIKit                               0x31c5a815 -[UITabBar(Static) _buttonUp:] + 81
    CoreFoundation                      0x33480571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 25
    UIKit                               0x31b7eec9 -[UIApplication sendAction:to:from:forEvent:] + 85
    UIKit                               0x31b7ee69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 33
    UIKit                               0x31b7ee3b -[UIControl sendAction:to:forEvent:] + 39
    UIKit                               0x31b7eb8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 357
    UIKit                               0x31b7f423 -[UIControl touchesEnded:withEvent:] + 343
    UIKit                               0x31b7dbf5 -[UIWindow _sendTouchesForEvent:] + 369
    UIKit                               0x31b7d56f -[UIWindow sendEvent:] + 263
    UIKit                               0x31b66313 -[UIApplication sendEvent:] + 299
    UIKit                               0x31b65c53 _UIApplicationHandleEvent + 5091
    GraphicsServices                    0x311a5e77 PurpleEventCallback + 667
    CoreFoundation                      0x334e7a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 27
    CoreFoundation                      0x334e983f __CFRunLoopDoSource1 + 167
    CoreFoundation                      0x334ea60d __CFRunLoopRun + 521
    CoreFoundation                      0x3347aec3 CFRunLoopRunSpecific + 231
    CoreFoundation                      0x3347adcb CFRunLoopRunInMode + 59
    GraphicsServices                    0x311a541f GSEventRunModal + 115
    GraphicsServices                    0x311a54cb GSEventRun + 63
    UIKit                               0x31b90d69 -[UIApplication _run] + 405
    UIKit                               0x31b8e807 UIApplicationMain + 671
    MyApp                              0x0009a188 main (main.m:5)

3 个答案:

答案 0 :(得分:3)

首先查看您的控制台日志。将显示一条消息,指出已发送哪个班级updateNumSections

确保您没有在后台线程上调用此表视图。这可能导致这些疯狂的崩溃。

确保表视图数据源未在表视图之前解除分配。

这里的怀疑是过度释放(正如你的建议),所以运行静态分析只是为了找到骨头的东西。还要确保使用访问器而不是直接使用ivars(过度发布的第一个原因)。

答案 1 :(得分:0)

我遇到了同样的问题,就像你在Rob Napier的评论中所建议的那样,它应该在tabBarController而不是viewDidDisappear上实现。

在乐器中运行Zombies将向您显示对取消分配对象的updateNumSections调用。

对于查找此问题的任何人,以下是您应该在tabViewController中使用的代码,给定一个在不再显示的选项卡中调用的navigationViewController。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    //Always go to the root controller when accessing a tab.
    //If any navigation controller that must remember its last state, change this for viewController == or !=
    if ([viewController isKindOfClass:[UINavigationController class]]) {
        [(UINavigationController*)viewController popToRootViewControllerAnimated:YES]; //Do not use code on disappear, instead popToRoot on tab selection
    }
}

答案 2 :(得分:0)

我很确定我不会在后台线程上更新表视图。

谢谢@Pierre-Francoys,我添加了一个Zombies Option,它告诉我发送给解除分配对象的选择器numberOfSectionsInTableView:。所以我在viewController中清除tableView的dataSource和delegate。而且效果很好。

- (void)dealloc {
    _tableView.dataSource = nil; 
    _tableView.delegate = nil;
}