Design and architecture of high-level applications

Over the past couple of years, I’ve done a lot of iOS development, so I’m very familiar with the architecture of iOS and application design (everything that allows the ViewController, which you either click, expose, or paste into the tab bar). Recently, I began to learn the correct development of applications for Mac and got a little lost. I would like it to be really just checked for sanity and maybe there was some advice as to which way to create such an application:

I would like to create a single-user library-style application that will create additional windows during its operation, but not as full-blown documents. The main window will be laid out just like OS X Lion Mail.app, with a three-way split view containing:

  • List of sources or high-level theme selection
  • A viewing a list of items related to the topic selected in the first panel
  • A detailed view that shows the details of the object selected in the middle pane.

As I said, it really looks like Mail.app how much it looks.

My question is how to glue all this from inside Xcode. Here, where my confusion still lies:

  • The default project created NIB with a main menu and a window. I like to encapsulate functionality, so I have to make a window controller for this window and somehow connect it to the Builder interface, or do any functions related to the window belong somewhere else?

  • If possible, I would like each of the three panels to be separate view controllers. I created three subclasses of NSViewController (Xcode automatically generated NIB) and added (to the main menu / NIB window) a look at controller objects with each specified class, connecting each view property to one of the three I went into NSSplitView. When I tried to install each controller of the NIB of the view, only the main menu / NIB window appeared in the drop-down list, and entering the desired manually seemed to have no effect (the contents of the view did not actually appear when the application started), It makes me think that I doing something wrong.

  • I am a little fuzzy what types of views I should use for each of the first two panels. I obviously create a custom one for the last panel, but it seems that the first two should already be present in the Cocoa framework.

In any case, if I am doing something completely wrong, do not worry when addressing my questions; just tell me what i should do instead. I think I just need a good Mac developer to point me in the right direction.

+4
source share
1 answer

As for your first question, you do not need to use the main window that Apple provides in MainMenu.xib. If you want, you can remove this window from nib and then create an instance of NSWindowController in your delegate method applicationDidFinishLaunching: which then loads and controls the main window.

You are definitely confused about the NSViewController , which is not really surprising since you can assume that it works like a UIViewController .

In fact, NSViewController completely different from UIViewController and does not have the same level of support for Interface Builder. For example, you cannot place a view controller in a window in IB, whereas this is standard practice for iOS. NSViewController is a relatively new class on the Mac, and you usually use it to load views programmatically and manage the contents of the view.

The class closest to the Mac UIViewController NSWindowController . This was much longer than the NSViewController , and in fact, many Mac applications do not use the NSViewController at all.

As a rule, each window in your application should have a window controller that controls it. You can use NSWindowController subclasses to handle many functions for each window.

If you want to use the NSViewController , then you must use your window controller to manage these view controller objects. This is usually done programmatically due to the aforementioned lack of support for Interface Builder. Each instance of NSViewController loads its view from a specific nib file. Usually you do not add view controllers in Interface Builder.

For your source list, you usually use NSOutlineView if you have multiple sections or an NSTableView . These two objects are used whenever you need a list of items. NSOutlineView is hierarchical, while NSTableView is flat.

Hope this helps.

+4
source

Source: https://habr.com/ru/post/1397904/


All Articles