且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

提出多个模态视图控制器?

更新时间:2023-02-12 11:41:31


尝试实现这一目标的简单方法是创建你希望以模态方式呈现并逐个呈现的VC

不幸的是,这不会奏效。你得到的只是VC提供的第一个
VC,其他所有人都无处可去。 UIKit不会在这里与你合作


http://xissburg.com/presenting-multiple-modal-view-controllers-at-once/

  UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0); 
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


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.

The trivial way to attempt to achieve that is to just create the VCs you want to present modally and present one after the other. Unfortunately, this is not gonna work. What you get is just the first VC presented, all others just go nowhere. UIKit just won’t cooperate with you here.

http://xissburg.com/presenting-multiple-modal-view-controllers-at-once/

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();