解散NSViewController在Swift中无效。

6

这是按钮的动作:

    @IBAction func readyPressed(sender: NSButton) {

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

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

1
尝试使用 self.dismissViewController(self)。 - swathy krishnan
4个回答

26

尝试使用以下代码行关闭窗口:self.view.window?.close()


即使您使用故事板segue(例如“Show”)打开NSViewController,似乎仍然需要使用这个。 - Clifton Labrum

2
您需要将按钮的操作添加到第一响应者中-dismissController:

screenshot


-1

你可以尝试使用

NSViewController().dismiss(vc).

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


-11

请尝试使用

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

或者使用

navigationController.popViewControllerAnimated(true)

如下所示

如何在Swift中关闭视图控制器


8
这不应该是被采纳的答案,因为这个问题是关于MacOS而不是iOS的。请仔细阅读,它没有说到 UIViewController 而是 NSViewController。 - Borzh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接