UiTabBarController在popToRootViewController上崩溃

时间:2012-03-31 15:44:38

标签: iphone ios uitabbarcontroller uitabbar uitabbaritem

选择标签时,我的应用程序崩溃了。这是崩溃的代码。

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[UINavigationController class]]) {
    [(UINavigationController*)viewController popToRootViewControllerAnimated:NO];
}


}

这是问题的代码。显然,当我使用popToRoot控制器时,会将消息发送到解除分配的对象。

DealElementDisplayController *dealElementDisplayController = [[DealElementDisplayController alloc] initWithStores:storeIds :YES];
            dealElementDisplayController.title = [NSString stringWithFormat:@"%@ Products", store.companyName];
            [self.navigationController pushViewController:dealElementDisplayController animated:YES];

这是个例外。

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xe0000008
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x3648af78 objc_msgSend + 16
1   UIKit                           0x320e809c -[UITableView(UITableViewInternal)             _createPreparedCellForGlobalRow:withIndexPath:] + 540
    2   UIKit                           0x320e717a -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1070
3   UIKit                           0x320e6904 -[UITableView layoutSubviews] + 200
4   UIKit                           0x3208b0d8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 176
5   CoreFoundation                  0x34fc81f4 -[NSObject performSelector:withObject:] + 36
6   QuartzCore                      0x36b53a9e -[CALayer layoutSublayers] + 210
7   QuartzCore                      0x36b536b6 CA::Layer::layout_if_needed(CA::Transaction*) + 210
8   QuartzCore                      0x36b5783c CA::Context::commit_transaction(CA::Transaction*) + 220
9   QuartzCore                      0x36b57578 CA::Transaction::commit() + 308
10  QuartzCore                      0x36b7f90a CA::Transaction::flush() + 38
11  QuartzCore                      0x36b7f8dc +[CATransaction flush] + 28
12  UIKit                           0x32096152 _afterCACommitHandler + 46
13  CoreFoundation                  0x3503db14 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
14  CoreFoundation                  0x3503bd50 __CFRunLoopDoObservers + 252
15  CoreFoundation                  0x3503c0aa __CFRunLoopRun + 754
16  CoreFoundation                  0x34fbf49e CFRunLoopRunSpecific + 294
17  CoreFoundation                  0x34fbf366 CFRunLoopRunInMode + 98
18  GraphicsServices                0x362bb432 GSEventRunModal + 130
19  UIKit                           0x320b5e76 UIApplicationMain + 

这是来自Zombie Profile的堆栈跟踪。我正在使用ARC。

   0 CoreFoundation ___forwarding___
   1 CoreFoundation _CF_forwarding_prep_0
   2 UIKit -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
   3 UIKit -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]
   4 UIKit -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:]
   5 UIKit -[UITableView layoutSubviews]
   6 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
   7 CoreFoundation -[NSObject performSelector:withObject:]
   8 QuartzCore -[CALayer layoutSublayers]
   9 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*)
  10 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
  11 QuartzCore CA::Transaction::commit()
  12 QuartzCore +[CATransaction flush]
  13 UIKit _afterCACommitHandler
  14 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
  15 CoreFoundation __CFRunLoopDoObservers
  16 CoreFoundation __CFRunLoopRun
  17 CoreFoundation CFRunLoopRunSpecific
  18 CoreFoundation CFRunLoopRunInMode
  19 GraphicsServices GSEventRunModal
  20 GraphicsServices GSEventRun
  21 UIKit UIApplicationMain

2 个答案:

答案 0 :(得分:0)

您的申请中出现异常的原因不是由于以下代码的问题

   - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
      {
        if ([viewController isKindOfClass:[UINavigationController class]]) {
        [(UINavigationController*)viewController popToRootViewControllerAnimated:NO];
      }
    }

我认为当您点击标签栏时,导航控制器弹出DealElementDisplayController,并再次释放DealElementDisplayController中未分配/已释放的变量之一。这可能是您崩溃的原因。检查-(void)dealloc中的DealElementDisplayController代码,确保您完成了所有操作。在仪器中使用zombie来检查异常。 zombie非常适合检测与内存管理相关的异常。

答案 1 :(得分:0)

这是因为当导航控制器已经在根控制器上时调用popToRootViewController。