首页 > 代码库 > iOS 跳转出现attempt to dismiss modal view controller whose view does not currently ……的解决方案

iOS 跳转出现attempt to dismiss modal view controller whose view does not currently ……的解决方案

今天在设置修改密码成功进行跳转到登录页面重新登录的时候,我写的原代码是:

 [self dismissViewControllerAnimated:YES completion:nil];
        
 [UIApplication sharedApplication].keyWindow.rootViewController = [[loginViewController alloc]init];

于是出现了在本页面跳到登录页面,然后又切回到本页面的状况。如图:

首先是修改密码的页面:

技术分享


点击确认以后,跳转到登录页面:


技术分享


但是在登录页面闪一下又回到了修改密码的页面:


技术分享


刚开始我很崩溃呀,后来在网上搜,也没有什么效果,自己捣鼓了一会儿,把代码改了一下就OK了,修改的代码是:

        // 销毁该控制器

[self dismissViewControllerAnimated:YES completion:nil];
        // 返回登陆首页
loginViewController *login = [[loginViewController alloc]init];
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
window.rootViewController = login;


iOS 跳转出现attempt to dismiss modal view controller whose view does not currently ……的解决方案