【问题标题】:Pushing a navigation controller after a modal view controller is presented在呈现模态视图控制器后推送导航控制器
【发布时间】:2014-10-09 08:12:44
【问题描述】:

我有一个标签视图控制器,它有一个像这样的按钮,当它被按下时会出现一个模式:

PostViewController *post = [[PostViewController alloc] init];

// [self.navigationController pushViewController:post animated:YES];

// Presentation
[self presentViewController:post animated:YES completion:nil];

当模式完成后,我想关闭它并像这样推送一个新的视图控制器:

ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[self.navigationController pushViewController:profile animated:YES];

但我不能在 post vc 中将其作为模态。我该怎么做?

【问题讨论】:

  • 为什么你需要在出现之前先呈现并关闭它?

标签: ios uiviewcontroller uinavigationcontroller uitabview


【解决方案1】:

您可以尝试使用completionBlock

在 presentViewController 完成时调用CompletionBlock

PostViewController *post = [[PostViewController alloc] init];
[con presentViewController:post animated:YES completion:^{
    ProfilesViewController *profile = [[ProfilesViewController alloc] init];
    [self.navigationController pushViewController:profile animated:YES];
}];

更多关于presentViewController:animated:completion:Apple Doc的信息

completion :演示完成后要执行的块。 这个块没有返回值,也没有参数。你可以 为这个参数指定 nil。

【讨论】:

  • 好的,所以它把它推到模态后面?
  • 它推入 navigationController 堆栈。
  • 如果你想之前关闭你的模态,你也可以使用completionBlock添加dismissViewControllerAnimated:completion:
  • 还有一个问题,一旦我关闭帖子,帖子数据可以显示在ProfilesViewController中吗?那么配置文件视图控制器在可见时会运行吗?
  • 当你关闭一个 ViewController 时,它会在里面 releases all data。因此,您必须向新 VC 提供要保留的所有参数。希望这能回答你的问题
【解决方案2】:

将标签视图控制器嵌入 UINavigationController 吗? 如果你没有,你当然不能使用 self.navigationController。

【讨论】:

    猜你喜欢
    • 2011-01-15
    • 2014-01-11
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多