【问题标题】:How can I dismiss a modal segue from interface builder in Xcode 10 and Swift 4 [duplicate]如何从 Xcode 10 和 Swift 4 中的界面构建器中解除模态序列 [重复]
【发布时间】:2023-03-17 12:08:02
【问题描述】:

我在 ViewController 中添加了一个按钮。这个视图控制器是用模态转场激活的。 我怎样才能从界面生成器中消除它。我必须使用 IBAction 还是可以从界面生成器中完成?

【问题讨论】:

  • 使用展开转场
  • 请您再解释一下您的问题
  • @AbhinavJha 当然。我有一个带有元素列表的表格视图控制器,它由导航控制器包装。在此视图中,我在导航栏中有一个“+”按钮,用于创建新项目。我想在模态 segue 中打开新项目视图。没关系。现在在新视图中,我在导航栏中有一个取消按钮和一个保存按钮。我无法解除转场并关闭此视图。
  • @Kobazzo,请在下面找到我的答案

标签: ios xcode swift4 xcode10


【解决方案1】:

试试下面的代码

override func viewDidLoad() {
    super.viewDidLoad()
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.leftNavigationItemAction(_:)))
}

@objc func leftNavigationItemAction(_ sender: UIBarButtonItem) -> Void {
    self.dismiss(animated: true, completion: nil)
}

【讨论】:

    【解决方案2】:

    斯威夫特 3:

    present(UIViewController(), animated: true, completion: nil)
    
    dismiss(animated: true, completion: nil)
    

    Swift 2.2:

    self.presentViewController(true, completion: nil)
    

    隐藏/关闭视图控制器:

    self.dismissViewControllerAnimated(true, completion: nil)
    

    希望这会有所帮助,谢谢。

    【讨论】:

    • 谢谢粉丝。完美的解决方案。
    猜你喜欢
    • 2012-01-02
    • 2011-12-28
    • 2011-08-16
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    相关资源
    最近更新 更多