views:

618

answers:

3

My App uses a modal view when users add a new foo. The user selects a foo type using this modal view. Depending on what type is selected, the user needs to be asked for more information.

I'd like to use another modal view to ask for this extra information. I've tried to create the new modal view like the first one (which works great) and it leads to stack overflow/“Loading Stack Frames” error in Xcode.

Am I going about this in completely the wrong way i.e. is this just a really bad idea? Should I rethink the UI itself?

UINavigationController *navigationController = [[UINavigationController alloc]   
    initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
+1  A: 

You need to take care on which instance you invoke the presentModalViewController when you deal with several levels of modal controllers. Let's suppose you have :

[myControllerA presentModalViewController:myControllerB animated:YES];

Next time you want to display a modal controller while B has the focus, you should invoke

[myControllerB presentModalViewController:myControllerC animated:YES];

in order to get the parent controller properly set. The hierarchy of controllers is then A-> B -> C

yonel
I ran into an issue where myControllerC wouldn't display if I made it a second child of myControllerA, but it works correctly if it's a child of myControllerB. Thanks!
Allen Pike
A: 

Did you try calling presentModalViewController on self.navigationControllerin both steps?

Felix
+3  A: 

Fixed. I got the behavior I wanted by pushing the second view controller to the first view controller's UINavigationController.

creation of 1st modal view

FooAddController *addController = [FooAddController alloc]
    initWithNibName:@"FooAddController" bundle:nil];
addController.delegate = self;
addController.foo = newFoo;
UINavigationController *navigationController = [[UINavigationController alloc]
    initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
[addController release];

creation of 2nd modal view (in FooAddController)

FooAddSizeViewController *addSizeController = [[FooAddSizeViewController alloc]
    initWithNibName:@"FooAddSizeViewController" bundle:nil];
addSizeController.delegate = self;
addSizeController.foo = self.foo;
[self.navigationController pushViewController:addSizeController animated:YES];
[addSizeController release];
NiKUMAN