views:

517

answers:

4

Hi, 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.

+1  A: 

Quite simply, you can't do that. Yanking the view out from under a UIViewController is a sure way to get a crash.

Look at the tab bar tutorials Apple provides to see how it's done properly.

Adam Ernst
A: 

This is a non trivial problem. Someone must have posted an example of removing a view from under a ViewController because a lot of people did it. And despite all the talk about how "bad" it was, it worked in 2.x. Even the apple article doesn't deal with architecture issue. Most people are going to write a .h/.m combination to handle each subcontroller view. The apple example seems to operate only in the .m file that controls the tabbarcontroller.

Flash Gordon
+1  A: 

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

Flash Gordon
That's exactly what I have done! :)
Ilya