Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序试图以模态方式呈现活动控制器?_Ios_Iphone_Objective C_Uiviewcontroller - Fatal编程技术网

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)可能会有所帮助。