views:

1214

answers:

2

In my SDK 3.0 core data based app, I have a tab bar controller managing 4 tabs. From time to time, apparently randomly, when I launch the app, it crashes with the following message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'

However, I am not modifying in my code any of the tabs except for the following. In practice, all of the navigation controllers or controllers in the tabs have been setup using IB, and in my code I have declared two of them as outlets, since I need to access them in my app delegate applicationDidFinishLaunching() method to setup their core data managedObjectContext as follows:

 [self managedObjectContext];
 [self managedObjectModel];
 [self persistentStoreCoordinator];
 [rootViewController retain];
 rootViewController.managedObjectContext = self.managedObjectContext;

Is this not correct? If so, why?

The only reference to the problem I have seen on the web is here:

http://discussions.apple.com/thread.jspa?messageID=9716886

However, the problem still persists even after deleting and recreating the tab bar controller from scratch in IB.

Any clue? Thanks in advance.

+2  A: 

I've had this problem too. Do you have an outlet to the UITabBar itself (not the UITabBarController) in the nib? When I removed that, I stopped having problems.

Sorry this isn't a 100% reliable explanation, but this workaround cleared the problem up for me.

Fraser Speirs
Thanks Fraser, at least for now your suggestion seems to solve the problem. The issue remains though.
unforgiven
A: 

I've gotten this exception a few times, especially when changing things with localizations. Cleaning the targets and then rebuilding seems to work around the issue.

Isaac
Yes, I also noticed this. Recently I had to add again an outlet to the UITabBar, and I started facing the problem again. I hope Apple will fix this, meanwhile the most important thing is that applications do not crash at runtime on actual devices.
unforgiven
Do NOT let this bug exist in your code. My game HexaLex hit this bug once every few hundred builds. I wasn't able to figure out a permanent fix but I didn't worry about it too much since it was so rare. Naturally, my App Store build for v1.0 was affected, utterly ruining my launch. After that happened I dug in and realized that at some point I'd connected an outlet to the UITabBar in Interface Builder. Heed my warning: stay FAR FAR away from the UITabBar!
n8gray