刚才遇到一个问题,如今在这就当纪录一下,你们有遇到的能快速找到缘由,分享一下啊。app
在APP中,须要用户登陆后才能使用,因此我经过更改APP的[UIApplicationsharedApplication].keyWindow.rootViewController来控制界面的跳转。spa
在使用过程当中出现以下问题:代理
1.登陆成功后点击注销按钮,弹出注销提示框UIAlertView;it
2.注销成功后从新登陆;io
3.再次点击注销再也不弹出UIAlertView。class
提示以下警告:登录
点击注销按钮执行更改rootvie操做:cli
attempt to dismiss modal view controller whose view does not currently appear方法
再次点击注销的时候提示:d3
Attempt to present <_UIModalItemsPresentingViewController: 0x7f9d1b5b2fd0> on <_UIModalItemAppViewController: 0x7f9d1d335520> whose view isnot in 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完全消失后再执行切换根控制器,解决!