0

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.

Rakesh Singh
  • 858
  • 1
  • 12
  • 31

2 Answers2

1

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];
Community
  • 1
  • 1
Kjuly
  • 34,476
  • 22
  • 104
  • 118
  • I did the changes as suggested, But this is causing my app to crash. Previosly only transition attribute was not obeyed and irrespective of what style I choose its always transition in default manner. – Rakesh Singh Dec 09 '11 at 12:02
  • Transition is happening correctly with [self popToViewController:element animated:YES]; But I want transition not to be of deafault but of UIModalTransitionStylePartialCurl. When I try your changes: [self.modalTransitionStyle= UIModalTransitionStylePartialCurl; [self presentModalViewController:element animated:YES]; App crashes. – Rakesh Singh Dec 09 '11 at 12:27
  • @RakeshSingh I'm sorry for my mistake. How about now? – Kjuly Dec 09 '11 at 13:25
  • No luck still. I want to use via pop view only. App is still crashing with BAD_MEMORY_EXCESS – Rakesh Singh Dec 09 '11 at 14:03
  • 4
    @RakeshSingh BAD_MEMORY_EXCESS, you mean EXC_BAD_ACCESS? Maybe you need to find out which one cause this crash, please see [THIS](http://stackoverflow.com/questions/8441390/crash-on-download-asynchronous-images-in-iphone-dev/8441568#8441568) answer to find it out. :) – Kjuly Dec 09 '11 at 16:16
  • Hi @Kjuly, The app is crashing with below Exception. 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller . – Rakesh Singh Dec 10 '11 at 09:51
1

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.

Community
  • 1
  • 1
pxlshpr
  • 986
  • 6
  • 15