提出多个模态视图控制器? [英] Present multiple modal view controllers?

查看:139
本文介绍了提出多个模态视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

我再次面临这个问题,并找到了另一种方法。如果呈现控制器未嵌入导航控制器中,则如果呈现的控制器不是全屏并且将变为黑色,则将隐藏它。方法setModalPresentationStyle:UIModalPresentationCurrentContext只能应用于导航控制器。因此,在UINavigationController中嵌入呈现控制器,将UIModalPresentationCurrentContext设置为它并呈现新控制器 - 您将获得对话框控制器。



我正在呈现搜索控制器,它具有推送的tableView堆栈详细控制器。



详细控制器可以显示带有消息的视图控制器,它由小UIView和半透明背景组成。



<问题:当最后一个视图控制器出现时,其下的所有视图控制器都变为隐藏状态,控制器显示搜索控制器变为可见。



这里我正在做的事情:

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

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

比表推送详细视图:

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

和详细视图显示消息框:

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

当它被解雇时,其下的所有控制器都可见。



更新:



所有我想要的是以模态方式呈现一个具有uitableview的视图控制器。从此表中显示将能够显示消息框的详细视图。消息框必须是另一个视图控制器。当显示消息框时,所有前两个控制器都会消失。这就是问题。

解决方案


尝试实现这一目标的简单方法是创建你希望以模态方式呈现并逐个呈现的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();

这篇关于提出多个模态视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆