【问题标题】:dismiss nsviewcontroller swift doesn't work关闭 nsviewcontroller swift 不起作用
【发布时间】:2015-03-07 17:36:00
【问题描述】:

这是按钮操作:

    @IBAction func readyPressed(sender: NSButton) {

    self.dismissController(Hardness)
    println(1)
    self.performSegueWithIdentifier("manual", sender: self)
    }

当我按下按钮时,println 工作,segue 工作,但 NSViewController "Hardness" 没有关闭

【问题讨论】:

  • 试试 self.dismissViewController(self)

标签: xcode macos swift nsviewcontroller


【解决方案1】:

试试这行来关闭窗口:self.view.window?.close()

【讨论】:

  • 这似乎是您使用的,即使您使用故事板 segue(例如 Show)打开 NSViewController
【解决方案2】:

您必须从按钮添加 Action 到 First Responder - dismissController:

【讨论】:

    【解决方案3】:

    你可以试试

    NSViewController().dismiss(vc).

    要关闭的视图控制器应作为参数传递,调用者可以是任何 NSViewController 对象。

    【讨论】:

      【解决方案4】:

      请尝试使用

      self.dismissViewControllerAnimated(true, completion: {});

      或使用

      navigationController.popViewControllerAnimated(true)

      这里介绍

      how to dismiss a view controller in swift

      【讨论】:

      • 这不应该是公认的答案,因为问题是针对 MacOS 而不是 iOS。请仔细阅读它不是说 UIViewController 而是 NSViewController。
      猜你喜欢
      • 2016-02-09
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多