I have a weird problem with something like-over-release in a tab bar app. My preliminary apologies for the complexity of describing this problem. Hope a small code example helps.
I have an application delegate MyAppDelegateconfigured as UITabBarControllerDelegate:
- (BOOL)tabBarController:(UITabBarController *)tabBarControllerIn shouldSelectViewController:(UIViewController *)viewController {
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarControllerIn didSelectViewController {
if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navController = (UINavigationController *)viewController;
[navController popToRootViewControllerAnimated:NO];
}
}
The view of the tab bar is configured using UINavigationControllerfor each of the 5 tabs. The root view controller (call it CrashingViewController) in the UINavigationControllerconfigured tab 4 is derived from UIViewControllerand conforms to the protocols UITableViewDataSourceand UITableViewDelegateto support a subcategory UITableView, which is just a 4-line table, each cell of which allows the user to switch to a different view. In -[UITableViewDelegate tableView:didSelectRowAtIndexPath:]:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ASubViewController1 *svc1;
ASubViewController2 *svc2;
ASubViewController3 *svc3;
ASubViewController4 *svc4;
switch (indexPath.row) {
case 1:
svc1 = [[ASubViewController1 alloc] init];
[self.navigationController pushViewController:svc1 animated:YES];
[svc1 release];
break;
case 2:
svc2 = [[ASubViewController2 alloc] init];
[self.navigationController pushViewController:svc2 animated:YES];
[svc2 release];
break;
default:
break;
}
}
, : , CrashingViewController. , ASubViewController2 . . , , . , UINavigationController, , . , UIKit - [ASubViewController2 SoSelector:] svc2 , .
, , - , ASubViewController2, ASubViewController* s? , svc2, - svc2 -, , . svc2 - , . UITableViewController - -, , a UIViewController? - ?
, - , , .
NSZombiesEnabled. , :
*** -[ASubViewController2 respondsToSelector:]: message sent to deallocated instance 0xe345cd0
backtrace:
#0 0x02a18fa7 in ___forwarding___ ()
#1 0x02a18e72 in __forwarding_prep_0___ ()
#2 0x003e69be in -[UITableView(UITableViewInternal) _spacingForExtraSeparators] ()
#3 0x003ede94 in -[UITableView(_UITableViewPrivate) _adjustExtraSeparators] ()
#4 0x003e6743 in -[UITableView layoutSubviews] ()
#5 0x027b9481 in -[CALayer layoutSublayers] ()
#6 0x027b91b1 in CALayerLayoutIfNeeded ()
#7 0x027b22e0 in CA::Context::commit_transaction ()
#8 0x027b2040 in CA::Transaction::commit ()
#9 0x027e2ebb in CA::Transaction::observer_callback ()
#10 0x02a88f4b in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#11 0x02a1db27 in __CFRunLoopDoObservers ()
#12 0x029e6ce7 in __CFRunLoopRun ()
#13 0x029e6350 in CFRunLoopRunSpecific ()
#14 0x029e6271 in CFRunLoopRunInMode ()
#15 0x0329200c in GSEventRunModal ()
#16 0x032920d1 in GSEventRun ()
#17 0x00380af2 in UIApplicationMain ()
#18 0x0000226a in main (argc=1, argv=0xbfffef64) at ~/main.m:16
2:
dealloc ASubViewController2 svc2 , 4 . dealloc.