开发者

How to chain modal views from a controller launched from UITabBarController

How would I go about chaining several modal controllers from a UITabBarController's view? The View Programming Guide from Apple says this is feasible but when I attempt such a task, I get the error,

"*Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UIWindowController.m:186

The Class hierarchy is something like this:

UITabBarController -> 1 child is a UIViewController inherited class named, Tab1Controller.

Tab1Controller -> orchestrates each of the 2 controllers that need to be presented modally. Launches 1 mod开发者_开发百科al UIViewController and when this finishes up (get called via a callback), dismisses it and then initiates another modal UIViewController.

It's as if there's not enough time between the two modal controllers ending and starting.

Is there any sample code that shows how to have one modal controller after another can be chained?


See my answer to this SO question:

Correct way of showing consecutive modalViews


It's as if there's not enough time between the two modal controllers ending and starting.

I think you've hit the nail on the head there. You cannot present a new modal view controller until the previous one has finished disappearing and the viewDidAppear: method is called on the view controller that had been being covered by the old modal view.

Another option would be to present the second modal view on top of the first, e.g.

[firstModalViewController presentModalViewController:secondModalViewController animated:YES]

You can then call [firstModalViewController dismissModalViewControllerAnimated:YES] to dismiss the second (returning to the first), or [self dismissModalViewControllerAnimated:YES] to dismiss both at once.


// present modal view inside another presented modal view

    FirstViewController *firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: firstVC];

    // Note: you can use your viewcontroller instead self.window.rootViewController

    [self.window.rootViewController presentViewController:navController animated:YES completion:^{
                //code...
                    SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

                    [navController presentViewController: secondVC animated:YES completion:nil];

                }
            }];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜