【问题标题】:dismissViewControllerAnimated is called but ViewController is not dismissed调用了dismissViewControllerAnimated,但没有解除ViewController
【发布时间】:2012-01-24 15:00:16
【问题描述】:

我遇到了dismissViewControllerAnimated 方法没有关闭视图的问题。

应用程序中发生的事情是:

  • ItemViewController 中的单元格被选中。
  • 视图被推送发送到ItemDetailViewController,详细信息通过代表发送
  • 用户选择“完成”并通过委托发送事件以在ItemViewController 中关闭

所有这些工作除了视图没有被解雇,没有错误。任何人都可以看出什么问题吗?

- (void)itemDetailViewControllerDidFinish:(ItemDetailViewController *)controller
{
    NSLog(@"Controller: %@", controller);
    // Returns - Controller: <ItemDetailViewController: 0x6b68b60>

    [self dismissViewControllerAnimated:YES completion:nil];
}

【问题讨论】:

  • 如果您改为发送dismissModalViewControllerAnimated: 会怎样?
  • self是如何被推入屏幕的?
  • @Vince:我确实尝试过,但如果 segue 是“推送”,它似乎不起作用。
  • Nekto:如果我理解正确的话,self === 控制器
  • @AdTaylor - self 不能被 VC 推送。向用户呈现秒的不就是VC吗?

标签: iphone objective-c ios ios4 ios5


【解决方案1】:

如果您改为拨打[controller.navigationController popViewControllerAnimated:YES] 会怎样?

就此而言,如果您调用[controller dismissViewControllerAnimated:YES completion:nil] 而不是自己调用呢?

【讨论】:

  • 对我有用的确切语法:[self.navigationController popViewControllerAnimated:YES];
  • 用 pop 推送,用dismiss 呈现
  • 如果您的页面嵌入在导航控制器中,self:dismissviewcontroller 似乎不起作用。
  • popViewController 工作得像个魅力
【解决方案2】:

答案在这个页面: dismissviewcontrolleranimated-vs-popviewcontrolleranimated

dismissViewController 在您没有导航控制器时使用。 很可能您正在使用导航控制器,然后使用 self.navigationController popViewController 代替。

还要注意 lemax 他的评论:使用 NULL, not nill for completionhandler

【讨论】:

  • 对非对象指针使用 NULL。所以你不应该在这里使用NULL。
【解决方案3】:

我在 iOS5 中遇到了一个问题,标准完成回调不允许视图完全关闭(仅该模式的当前推送视图)

[controller dismissViewControllerAnimated:YES completion:^ {
     //
 }];

iOS5 的解决方案是没有回调:

[controller dismissViewControllerAnimated:YES completion:nil];

【讨论】:

    【解决方案4】:

    在调用 dismissViewControllerAnimated 时遇到问题,在 UIViewController 中关闭了键盘,但不是视图本身。

    通过使用两个调用解决了它:

    [self dismissViewControllerAnimated:NO completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
    

    一个即时的键盘,然后一个动画的控制器

    【讨论】:

      【解决方案5】:

      您的情况是 - ItemViewController -> ItemDetailViewController (按导航控制器) Self.dismissViewController(..) 关闭在 self 上呈现的视图控制器(在您的情况下是 ItemViewController)。在这里,你没有在 self 上展示任何 VC,而是在导航堆栈上推送了一个新的 VC。因此,关闭 ItemDetailViewController 的正确方法是

      self.navigationController.popViewController(true)。请阅读dismissViewController(....) 的描述以获得更清晰的说明。

      【讨论】:

        猜你喜欢
        • 2013-07-12
        • 1970-01-01
        • 2020-04-08
        • 2015-02-18
        • 2018-10-25
        • 1970-01-01
        • 1970-01-01
        • 2019-08-31
        • 1970-01-01
        相关资源
        最近更新 更多