Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 889
chanjianyi Avatar asked Oct 23 '18 04:10

chanjianyi


People also ask

What is the difference between View and Controller?

The view renders presentation of the model in a particular format. The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.


1 Answers

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

like image 180
Marc T. Avatar answered Sep 28 '22 07:09

Marc T.