刚才遇到一个问题,现在在这就当纪录一下,大家有遇到的能快速找到原因,分享一下啊。

在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 isnot in the window hierarchy!

我的代码是:

    LoginViewController *loginVC = [[LoginViewControllerallocinit];

            CNavigationController *nav = [[CNavigationControllerallocinitWithRootViewController:loginVC];

            [UIApplicationsharedApplication].keyWindow.rootViewController = nav;

造成这个的原因主要是

  因为我执行上述代码是在:-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex的这个方法执行的;

  所以在我执行切换根视图控制器的时候UIAlertView是还没有消失的,所以会出现上述错误,UIAlertView的消失是需要一定的时间的,

解决方案:

要解决这个问题,就是在UIAlertView的另一个代理方法-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex中执行切换根 控制器的操作,即上述我的代码,也就是说在UIAlertView彻底消失后再执行切换根控制器,解决!

 

相关文章:

  • 2022-01-11
  • 2021-08-12
  • 2021-06-01
  • 2021-06-11
  • 2022-12-23
  • 2021-08-15
  • 2021-08-17
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-11-02
  • 2021-05-12
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案