您的位置:首页 > 移动开发 > IOS开发

iOS开发注销操作后更改rootViewController的问题

2015-09-09 17:06 579 查看
刚才遇到一个问题,现在在这就当纪录一下,大家有遇到的能快速找到原因,分享一下啊。

在APP中,需要用户登录后才能使用,所以我通过更改APP的[UIApplicationsharedApplication].keyWindow.rootViewController来控制界面的跳转。

在使用过程中出现如下问题:

1.登录成功后点击注销按钮,弹出注销提示框UIAlertView;

2.注销成功后重新登录;

3.再次点击注销不再弹出UIAlertView。

提示如下警告:

点击注销按钮执行更改rootvie操作:

attempt to dismiss modal view controller whose view does not currently appear
再次点击注销的时候提示:
Attempt to present <_UIModalItemsPresentingViewController: 0x7f9d1b5b2fd0> on <_UIModalItemAppViewController: 0x7f9d1d335520> whose view isnotin
the window hierarchy!
我的代码是:

LoginViewController *loginVC = [[LoginViewControlleralloc]init];
            CNavigationController *nav = [[CNavigationControlleralloc]initWithRootViewController:loginVC];
            [UIApplicationsharedApplication].keyWindow.rootViewController
= nav;
造成这个的原因主要是:因为我执行上述代码是在:-(void)alertView:(UIAlertView
*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex的这个方法执行的,所以在我执行切换根视图控制器的时候UIAlertView是还没有消失的,所以会出现上述错误,UIAlertView的消失是需要一定的时间的,
解决方案:
要解决这个问题,就是在UIAlertView的另一个代理方法-(void)alertView:(UIAlertView
*)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex中执行切换根控制器的操作,即上述我的代码,也就是说在UIAlertView彻底消失后再执行切换根控制器,解决!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息