Presenting view contro…

来源:互联网 发布:web服务器搭建域名 编辑:程序博客网 时间:2024/05/19 13:55

模态跳转的时候有时会会出现这个警告

Presenting view controllerson detached view controllers is discouraged .


原因是present出来的模态窗口,禁止再使用present 来弹出其它的子窗口

只要把self直接模态跳转页面改成从根控制器跳转即可

例如:

 

 PicDetailViewController *detailVC= [[PicDetailViewController allocinit];

[self presentViewController:detailVC animated:YES completion:nil];

改成

  AppDelegate *delegate= (AppDelegate *)[UIApplication sharedApplication].delegate;

 [delegate.window.rootViewController presentViewController:detailVC animated:YEScompletion:nil];

即可

引申一下如何找根控制器:

方法一:就是通过上面的方法,先找到appdelegate然后获取window属性

  LeftSlideViewController *rootVc= (LeftSlideViewController*)[(AppDelegate *)[UIApplication sharedApplication].delegate window].rootViewController;

这种方法除了找根控制器还能找appdelegate类里的定义的任何属性,如:

方法二:直接通过keyWindow来找根控制器,更直接

 

  LeftSlideViewController *rootVc= (LeftSlideViewController*)[UIApplicationsharedApplication].keyWindow.rootViewController;


0 0
原创粉丝点击