"The application tried to introduce a modally active controller?"

I just ran into a crash, showing an NSInvalidArgumentException with this message in an application that had not been done before.

The application tried to introduce a modally active UITabBarController: 0x83d7f00.

I have a UITabBarController that I create in AppDelegate and assign it an array of UIViewControllers .

One of them that I want to introduce when he tapped it. I did this by running the delegate method

 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController 

If this view controller belongs to the class of the one I want to represent modally, I return NO and do

 [tabBarController presentModalViewController:viewController animated:YES]; 

And now I get this error, which apparently means that you cannot modally represent a view controller that is active somewhere else (on the tab ...) I have to say that I'm on Xcode 4.2 Developer Preview 7, so this is iOS 5 (I know about NDA, but I think that I do not give any forbidden data). I currently do not have an Xcode installation to check if it will compile with the iOS4 SDK, but I am almost completely sure that it does not.

I just wanted to ask, did anyone experience this problem or have any suggestion

+77
ios objective-c ios5
Sep 15 2018-11-11T00:
source share
5 answers

Suppose you have three instances created this way:

 UIViewController* vc1 = [[UIViewController alloc] init]; UIViewController* vc2 = [[UIViewController alloc] init]; UIViewController* vc3 = [[UIViewController alloc] init]; 

You have added them to the tab bar, for example:

 UITabBarController* tabBarController = [[UITabBarController alloc] init]; [tabBarController setViewControllers:[NSArray arrayWithObjects:vc1, vc2, vc3, nil]]; 

Now you are trying to do something like this:

 [tabBarController presentModalViewController:vc3]; 

This will give you an error message because this tab bar controller has death control on the view controller that you gave it. You cannot add it to the array of view controllers in the tab bar, or you cannot present it in text format.

Apple expects you to relate to your user interface elements in a certain way. It was probably buried in the Human Interface Guide somewhere "do not do this because we do not expect you to ever want to do this."

+80
Sep 23 '11 at 19:44
source share

I have the same problem. I am trying to submit a view controller right after the rejection.

 [self dismissModalViewControllerAnimated:YES]; 

When I try to do this without animation, it works fine, so the problem is that the controller is still alive. I believe the best solution is to use dismissViewControllerAnimated:completion: for iOS5

+11
Dec 06 '11 at 5:11
source share

I had the same problem. I allow her. You can try this code:

 [tabBarController setSelectedIndex:1]; [self dismissModalViewControllerAnimated:YES]; 
+2
Apr 30 '13 at 9:49 on
source share

In my case, I tried to present the viewController (I have a viewController link in the TabBarViewController) from different view controllers, and it crashes with the above message. In this case, you can use

viewController.isBeingPresented

 !viewController.isBeingPresented { // Present your ViewController only if its not present to the user currently. } 

May help someone.

+2
Jul 13 '18 at 3:50
source share

Just uninstall

 [tabBarController presentModalViewController:viewController animated:YES]; 

and save

 [self dismissModalViewControllerAnimated:YES]; 
0
Oct 18 '11 at 12:59
source share



All Articles