Group Group Group Group Group Group Group Group Group
raywenderlich.com Forums

Windows and Window Controllers in OS X Tutorial

Learn the basics of building apps for OS X with this Windows and Window Controllers in OS X tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1459-windows-and-window-controllers-in-os-x-tutorial

Great tutorial! One place where tutorials like this tend to leave me hanging is how to get the connections between the model and what could be deeply-nested NSViewController subclasses. Imagine you have a window with a tab control and three view controllers (one per tab). You want to connect the leaf view controller to the data model, but you really don’t want to imbue it with more knowledge about the app structure than it needs. Ideally, you’d inject from the top-down just the part of the model that each particular view controller needs.

But you don’t want to necessarily do that all at once; you just want it to happen when each view controller loads. Is this even possible?

For anyone that’s interested in using “modal session” instead of “run modal”, here’s a swift version of the Objective-C example within the Apple Developer Reference page.

The only difference here from the example is that I used the window object (NSWindow) method, “close()”.

func runModalWindow(){

    let application = NSApplication.sharedApplication()

    let session = application.beginModalSessionForWindow(self.window)

    for(;;){
        if( application.runModalSession(session) != NSModalResponseContinue){
            break
        }
    }

    window.close()

    application.endModalSession(session)
}

For anyone bothered by the document window not regaining focus after the word count window is closed, you can fix it by adding
self.view.window?.makeKeyAndOrderFront(nil)
right after the call to runModalForWindow.

In today’s date, most of the people know about it, so for that if you interested in it then you will get some review by which you will be very helpful. Faced any type of issue with windows, then for you I have Windows update error code 8007000e, you just browse and get more help.