Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present multiple modal view controllers?

update:
I've faced this problem again, and found another way. If presenting controller is not embedded in navigation controller, it will be hidden if presented controller is not fullscreen and will became black. Method setModalPresentationStyle:UIModalPresentationCurrentContext can be applied only to navigation controller. So embed presenting controller in UINavigationController, set UIModalPresentationCurrentContext to it and present new controller - you will get dialog controller.

I'm presenting search controller, it have tableView that push on stack detailed controller.

Detailed controller can present view controller with message, it consists from small UIView and semitransparent background.

Problem: when last view controller presented, all view controllers under it becomes hidden and controller, that presented search controller becomes visible.

Here what I'm doing:

SearchViewController *viewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
viewController.data = dataArray;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
[self.navigationController presentViewController:navigationController animated:YES completion:nil];

than table pushes detailed view:

DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[viewController setHidesBottomBarWhenPushed:YES];
viewController.dataItem = [data objectAtIndex:(NSUInteger) [indexPath row]];
[self.navigationController pushViewController:viewController animated:YES];

and detailed view presenting message box:

MessageController *controller = [[MessageController alloc] initWithNibName:@"MessageController" bundle:nil];
controller.message = message;
[self presentViewController:controller animated:YES completion:nil];

When it's dismissed, all controllers under it became visible.

update:

all I wanted is to present modally a view controller that will have uitableview. From this table to show detailed view that will be able to show message box. Message box must be another view controller. And when message box is shown all two preceding controllers disappears. that is the issue.

like image 824
trickster77777 Avatar asked Nov 01 '13 09:11

trickster77777


People also ask

How do I present a two view controller in Swift?

For solving this, you will need to do a pretty simple trick which is to take a screenshot from the first view controller and passing it to the second view controller to display it while presenting the third view controller. You can check this repository to see how it is exactly could be done (Swift 3).


2 Answers

In some situations, you could have each modally presented view controller present the next one.

let window = UIApplication.sharedApplication().keyWindow!
if let modalVC = window.rootViewController?.presentedViewController {
    modalVC.presentViewController(vc, animated: true, completion: nil)
} else {
    window.rootViewController!.presentViewController(vc, animated: true, completion: nil)
}
like image 114
SlimeBaron Avatar answered Sep 24 '22 16:09

SlimeBaron


Dismiss all view controllers above the presented view controller.

Apple's documentation follows:

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

Dismiss two modal view controllers.

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:NULL];

https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#jumpTo_51

like image 39
Rei Kubonaga Avatar answered Sep 25 '22 16:09

Rei Kubonaga