开发者

iPhone - dismiss parent modal view

I am sketching out the workflow of an app开发者_运维技巧 where you have a main menu 'Level 0' that calls a modal view 'Level 1', which calls another modal view 'Level 2'.

I am able to get this working, no problem AND I am able to dismiss the entire stack by using:

[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];

in the modal view 'Level 2'.

My problem is when modal view 'Level 2' has a navigation bar I cannot dismiss the entire stack. The code I listed above only brings me back one level so it really acts the same as if I had done this:

[self dismissModalViewControllerAnimated:YES];

on modal view 'Level 2'.

Summary: When modal view 'Level 1' calls modal view 'Level 2' using the following:

Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease];  
[self presentModalViewController:portalMainController animated:YES];

I can dismiss the entire stack and get back to the main menu (Level 0). BUT when 'Level 1' calls 'Level 2' with a navigation bar like the following:

 Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease];  
 UINavigationController *navigationController = [[UINavigationController alloc]    initWithRootViewController:level2];
 [self presentModalViewController:navigationController  animated:YES];
 [navigationController release];

I cannot get back to 'Level 0', I only get back to 'Level 1'.

Any suggestions?


I would create a protocol for the level 2 controller such as Level2Delegate. Then set the delegate of the level 2 controller to be the level 1 controller. Then you could do something like the following:

Level 2 controller would implement this where self.delegate is the level 1 controller

[self.delegate controllerDidFinish:self];

Level 1 would implement:

- (void)controllerDidFinish:(Level2Controller *)controller {
    [[self parentViewController] dismissModalViewControllerAnimated:NO];
}

The key is to set up a chain of events rather than trying to dismiss both at once.


Why not using,

[self.navigationController popToRootViewControllerAnimated:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜