chanjianyi
chanjianyi

Reputation: 615

Why the view controller not follow the window controller's appearance in segue "Modal"?

there is a window controller connected to the view controller

when the menu item click I want to show that window as modal

enter image description here

after that the window is show, but I found that the view controller not follow the window controller's appearance

enter image description here

also any window controller appearance is not working.. including content size, window title... etc

So what is the problem?

Upvotes: 8

Views: 585

Answers (1)

Marc T.
Marc T.

Reputation: 5340

Consider that you are presenting only the view controller and not any related window controller you define if you use presentAsModalWindow(_ viewController: NSViewController)

The viewController is made the delegate and contentViewController of the window while it is shown

You could make the window customisations in viewWillAppear of your custom view controller

    override func viewWillAppear() {

    let closeButton = view.window?.standardWindowButton(.closeButton)
    closeButton?.isHidden = true

}

In viewDidLoad the window property will be still nil.

If you want to present your window controller do something like this triggered my your menu item.

    @IBAction func showMyWindowController(sender:NSMenuItem){

    let storyboard = NSStoryboard(name: "Main", bundle: nil)
    let windowController = storyboard.instantiateController(withIdentifier: "MyWindowController") as! NSWindowController

    windowController.showWindow(self)

}

Hope this helps

Upvotes: 5

Related Questions