加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Application tried to present modally an active controller

(2013-01-21 22:49:43)
标签:

presentviewcontrolle

it

分类: 错误分析

今天写页面调用presentViewController方法时遇到这样的错误。

 

'Application tried to present modally an active controller .'


大概原因也是像描述的那样,就是我们调用显示当前的VC(viewController)。

这可怎么办?
先搞清楚我的大致环境吧。
1.程序中的UITabBarController是自己写的一个VC

 

    self.window.rootViewController = _tabBarController;

self.tabBarController.tabBar.hidden = YES;

    ... ...

    [self.tabBarController.view addSubview:_barController.view];


2.需要调用presentViewController方法的页面,也是由多个VC组合到该页面中去的。

鉴于这种情况,
1.直接用方法:

[self presentViewController:filmRootView 

                       animated:YES

                     completion:^(void){

                         // Code

                         

                     }];


http://s12/mw690/7b9d64aftd3ce1eeede9b&690tried to present modally an active controller" TITLE="Application tried to present modally an active controller" />

不能够达到目的,因为,多个VC都集中在该页面中,所以,无法完成。

2.使用另一种方法

FilmRootView *filmRootView = [[FilmRootView alloc] init];

    [filmRootView refreshData:self.arrForPhoto];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:filmRootView];

    [filmRootView release];

    

    [filmRootView setModalTransitionStyle:UIModalPresentationFullScreen];



    

    [self presentViewController:navigationController

                       animated:YES

                     completion:^(void){

                         // Code

                         

                     }];


    [navigationController release];


http://s5/mw690/7b9d64aftd3ce0de7a924&690tried to present modally an active controller" TITLE="Application tried to present modally an active controller" />
显然不行。而且成了“夹心饼干”。仔细看代码,还是跟第一种类似,只不过,是重新声明了一个UINavigationController,并且更加糟糕。
其实,也还是第一种情况,多个VC并存下,导致,无法将新的VC,弹出到单独的页面。

不放弃!查啊!查!!!
大概这种情况很怪,确实没有查到什么!
不放弃!
继续找!

灵光一闪………………
于是,恍然大悟:
既然这个VC,由多个VC构成,那么,应该找到“根VC”,用“根VC”来调用presentViewController方法。

所以,在程序中,先找到根VC:

- (id)getCurNavController{

    UINavigationController* navController = (UINavigationController*)self.tabBarController.selectedViewController;

    return navController;


}


用返回的“根VC”,来调用presentViewController方法

FilmRootView *filmRootView=[[FilmRootView alloc] init];

    [filmRootView refreshData:self.arrForPhoto];

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

    UINavigationController *theNavController= [_appDelegate getCurNavController];

    

    

    [theNavController presentViewController:filmRootView

                       animated:YES

                     completion:^(void){

                         // Code

                         

                     }];


成功!
我了个汗啊!起码绕了很久,必须mark一下!

希望对你有所帮助!

无意间,又翻出来看,发现,做一个修正。
这样做也是可以的。

根VC+ UINavigationController

FilmRootView *filmRootView=[[FilmRootView alloc] init];

    [filmRootView refreshData:self.arrForPhoto];

    

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:filmRootView];

    [filmRootView setModalTransitionStyle:UIModalPresentationFullScreen];

    [filmRootView release];

    

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

    UINavigationController *theNavController= [_appDelegate getCurNavController];

    

    

    [theNavController presentViewController:navigationController

                       animated:YES

                     completion:^(void){

                         // Code

                         

                     }];



还是多看API好处多多啊!




0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有