I have an application that perfectly works on iPhone os 2.2.1 but when I try to run it on iPhone os 3.0 it crushes.
Here is the error I got from the console:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Changing the delegate of a tab bar managed by a tab bar controller is not allowed.'
Probably it occurs because I am changing the view of a certain view controller programmatically.
Here is the code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
self.view = current_controller.view;
[current_controller viewWillAppear: NO];
[current_controller viewDidAppear: NO];
}
May an error occur in this part of code and if yes how can I fix it? Why else could it occur?
Thank you in advance, Ilya.
In most cases you can use UITabBarControllerDelegate instead. It has similar methods to UITabBarDelegate and avoids such exception. For, example, instead of:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
int index = [tabBar determinePositionInTabBar:item]; // custom method
[tabBar doSomethingWithTabBar];
[item doSomethingWithItem];
[item doSomethingWithItemAndIndex:index];
}
you can write:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UITabBarItem *item = [tabBarController.tabBar selectedItem];
int index = [tabBarController.tabBar determinePositionInTabBar:item]; // custom method
[tabBarController.tabBar doSomethingWithTabBar];
[item doSomethingWithItem];
[item doSomethingWithItemAndIndex:index];
}
Mr. Ernst above gives the impression that he sees something in Ilya's code that constitutes "yanking a view out from under a Controller". That can have you staring at code for a long time and that isn't where the problem really is. I posted this problem on the Apple Developer Forum http://discussions.apple.com/message.jspa?messageID=10259835#10259835 and I was told that 'NSInternalInconsistencyException' is a problem with a .xib file (In the Interface Builder). Using this information I found the following solution. I think some of the name's I give here are generic and will give help to others trying to fix this problem. To review the problem, the xib reference compiles and runs perfectly on 2.x, compiles on 3.x and gives the error message above when you try to run the application in the 3.0 simulator. I had a delegate in a tab bar. In viewing the Referencing Outlets in Interface Builder I had "Multiple", "File's Owner", "Tab Bar", and "Tab Bar Controller" as the referencing outlets. When I removed "Tab Bar" from the Referencing Outlets my app ran in Simulator 3.0. It also compiled and ran on 2.x so the "Tab Bar" reference was not required by 2.x. ... Flash Gordon
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With