0
votes

I have Navigation interface which I use to pop to setting screen everytime uses presses settings button.

@interface Navigation : UINavigationController
{
}
-(void)popToMainMenuAnimated:(BOOL)animated;

//.m file
-(void)popToMainMenuAnimated:(BOOL)animated
{
    UIViewController *element;
    for(element in self.viewControllers)
    {
        if([element isKindOfClass:[MainSettingClass class]]){
          self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
          [self presentModalViewController:element animated:YES]
        }
     }
}

App is crashing with below Exception.

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .' * First throw call stack:

NOTE: This not root screen but 3rd sceen of my application.

2

2 Answers

1
votes

Base on the debug log you gave I got a reason by searching:
MainSettingClass instance that you pushed before can neither be repushed to the array on navigationController again, nor be presented modally. You should create a new MainSettingClass instance and present it, just like the second code snippet.

HERE is a relate question that mentioned Application tried to present modally an active controller. :)

-(void)popToMainMenuAnimated:(BOOL)animated
{
    UIViewController *element;
    for(element in self.viewControllers) {
        if([element isKindOfClass:[MainSettingClass class]]) {
            self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
            [self presentModalViewController:element animated:YES];
            break;
        }
    }
}

But why not load the Main Menu instead of pop?

-(void)loadMainMenuAnimated:(BOOL)animated
{
    MainSettingClass * mainMenuViewController = [[[MainSettingClass alloc] init] autoreleased];
    [mainMenuViewController.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
    // ...
    self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    [self presentModalViewController:mainMenuViewController animated:YES];
}

And the code you show has some mistakes:

self.modalTransitionStyle= UIModalTransitionStylePartialCurl;
[self popToViewController:element animated:YES];

self.modalTransitionStyle= UIModalTransitionStylePartialCurl; if you set this one, you need use

[self presentModalViewController:yourViewController animated:YES];

not

[self popToViewController:element animated:YES];
1
votes

It appears that the 'MainSettingsClass' UIViewController you're picking out and attempting to present (modally) is already active. It would help if you put up the code where this view controller may have been previously pushed/presented (and ideally popped/dismissed).

Here are a couple of related questions that might help you.