【问题标题】:How dismiss a viewController with storyboard from a push segue?如何从 push segue 中解散带有情节提要的 viewController?
【发布时间】:2012-05-03 17:40:01
【问题描述】:

我不知道为什么dismissViewControllerAnimated:completion:。我只是想做。

我从一个

开始
[self performSegueWithIdentifier:@"my_segue" sender:self];

但是我称之为解雇比什么都没有发生。我可以创建另一个 segue,但它会创建一个新的视图控制器。

我的问题是:如何解散performSegueWithIdentifier:sender:

【问题讨论】:

    标签: iphone objective-c cocoa-touch storyboard segue


    【解决方案1】:

    在调用的 viewController 中是否有一个导航栏:

    [self performSegueWithIdentifier:@"my_segue" sender:self];
    

    如果是这样,您将需要使用:

    [self.navigationController popViewControllerAnimated:YES];
    

    从堆栈中弹出视图。有一个 segue 调用,但框架似乎调用:

    presentViewController:animated:completion:
    

    或:

    pushViewController:animated:
    

    视情况而定。

    【讨论】:

    • 我正在尝试以dismissViewController 为中心的不同组合....它们都不起作用。很高兴我找到并尝试了您对“popViewController”的建议。不确定这是否属实,但我当然可以看到 PUSH segue 与需要互惠 POP 以将其从堆栈中移除之间的可能关系。
    【解决方案2】:

    你可以打电话

    [self dismissViewControllerAnimated:YES completion:nil];
    

    来自视图控制器,因为视图控制器是由 segue 推送的。

    【讨论】:

      【解决方案3】:

      [my_segue_view_controller dismissModalViewControllerAnimated: YES]?

      (不确定,但在我的实践中有效)

      【讨论】:

      • 您应该避免使用dismissModalViewControllerAnimated:,因为the docs 说它已被弃用。应该改用dismissViewControllerAnimated:completion:
      【解决方案4】:

      performSegueWithIdentifier:sender: 本身并没有被解除,这只是被调用来启动命名的 segue 的方法。 segue 中发生的事情更有趣。

      你说得对,你应该调用dismissViewControllerAnimated:completion:,它应该由presenting视图控制器调用,它之前使用@调用了presented视图控制器987654324@。如需更多信息,请参阅the UIViewcontroller docs

      【讨论】:

        【解决方案5】:

        Swift 4 版本使用以下代码

          self.navigationController?.popViewController(animated: true)
        

        【讨论】:

          猜你喜欢
          • 2012-05-20
          • 1970-01-01
          • 1970-01-01
          • 2011-12-26
          • 2017-08-03
          • 1970-01-01
          • 2020-06-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多