Difference between NSWindowController Vs NSViewController

前端 未结 3 1909
逝去的感伤
逝去的感伤 2021-02-03 22:55

I am coming from iOS background and starting to learn Cocoa. On iOS unless we have multiple targets for iPad and iPhone

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-03 23:22

    I also come from iOS and started coding Mac apps a while ago, learning mostly from Apple's documentation.

    My impression is that on the desktop, you almost never need NSViewControllers (one big exception would be a window with tabs and multiple views, like the GarageBand welcome screen).

    Most of the time you have one NSWindowController per window. Learn first the relation between NSWindow and NSWindowController (and NSDocument, if you are making a document-based app).

    Once you got that right, start experimenting with NSViewController.


    UPDATE: It seems that since the introduction of storyboards for mac apps too, Apple expects that most of the view presentation logic should be migrated from the older NSWindowController to the newer NSViewController, more in line with how an iOS app is structured. I am not very knowledgeable on exactly where to draw the line, or what kind of code should remain in the window controller (or whether it still needs to be subclassed at all).

提交回复
热议问题