Ios 应用程序试图以模态方式呈现活动控制器?
我得到一个错误:Ios 应用程序试图以模态方式呈现活动控制器?,ios,iphone,objective-c,uiviewcontroller,Ios,Iphone,Objective C,Uiviewcontroller,我得到一个错误: Application tried to present modally an active controller 当我尝试运行下面的代码时 我想展示一个内嵌在UINavigationController中的模态视图控制器。在此之前,我已经实例化了navigationVC。我只有在第二次运行此代码时才会出现此错误。我的意思是,如果我点击一个按钮,它运行这个代码,它将正常工作。我可以关闭这个视图。如果我再次单击同一按钮以再次运行它,则会出现错误 - (void)pushToUs
Application tried to present modally an active controller
当我尝试运行下面的代码时
我想展示一个内嵌在UINavigationController
中的模态视图控制器。在此之前,我已经实例化了navigationVC
。我只有在第二次运行此代码时才会出现此错误。我的意思是,如果我点击一个按钮,它运行这个代码,它将正常工作。我可以关闭这个视图。如果我再次单击同一按钮以再次运行它,则会出现错误
- (void)pushToUserProfile
{
if (!self.profileVC) {
self.profileVC = [self.storyboard instantiateViewControllerWithIdentifier:@"profileVC"];
[self.profileVC setCanEditProfile:NO];
[self.profileVC setTitle:@"Profile"];
[self.profileVC setCanCloseModal:YES];
}
[self.navigationVC setViewControllers:@[self.profileVC]];
[self presentViewController:self.navigationVC animated:YES completion:nil];
}
下面我做错了什么
编辑:
我还运行代码:
- (void)writeComment
{
if (!self.writeCommentVC) {
self.writeCommentVC = [self.storyboard instantiateViewControllerWithIdentifier:@"writeCommentVC"];
}
[self.navigationVC setViewControllers:@[self.writeCommentVC]];
[self presentViewController:self.navigationVC animated:YES completion:nil];
}
而且它毫无问题地工作。无论我显示/关闭该视图控制器多少次。是否从
self.navigationVC
显示self
?@rmaddy self未从self.navigationVC显示。self下面有navigationVC。还可以查看我的编辑。也许self.profileVC
已在视图中,您可以尝试再次显示它。请尝试[self.navigationController presentview controller:self.newController animated:YES completion:nil];或[self-presentViewController:self.newController动画:是完成:无];-为什么要通过代码设置viewController?您不能在xcode中进行可视化管理吗?这是一种较少的错误预防措施self.navigationVC被忽略的代码(writeCommentVC和profileVC)可能会有所帮助。