With introduction of the iPhone SDK, Apple seemed to introduce new programming model or new way of organizing UIs and coding structure.
Due to them programming for iPhone and iPod touch looks different than that for Mac. One strength of iPhone SDK is that Mac programmers can transfer their skill set to iPhone very easily. However, because they are very similar, it is also prone to forget how they have written codes for the Mac. So, somehow Apple should design upcoming version of SDKs for Mac and the iPhone to make them abide by same programming model and flow.
One of those is view controllers. With iPhone SDK and Leopard SDK, they introduced view controllers, or NSViewController and UIViewController. As their names suggest what they do is to manage views. Although their purpose is explained quite thoroughly at KATI’s blog, it was a little difficult for me to read it. So, I would like to briefly define what they are.
The view controllers are for managing views. Current trend in UI design is Single Window, Multiple View. What it means is that there is one Window and inside of it, different group of views designed for different purpose can be swapped in and out. So, the View Controllers handles these for programmers for well-established pattern.
Currently view controllers are very important for iPhone and iPod touch programming, because the platform is based on Single-Window and Multiple View model. However, it doesn’t seem to me that using view controller is very popular for Mac. ( Again, it is a new trend. So, people who want to adopt it will use the view controllers. I hope that Apple provides some sample using the view controllers. ( Did they do so already? ) However, people can always take a look at sample codes for iPhone and get the idea.
Then, how about the window controller like NSWindowController? Its counterpart, UIWindowController doesn’t exist for the iPhone and iPod touch environment, because there is only one window for those environment.
Unlike view controllers, the NSWindowController is for document based programs. Well, document based program can use multiple window. So, it is reasonable to think that NSWindowController is for document based programs as Apple’s document says.
Here, I would like to mention about the hierarchy of NSWindow, NSView, and UIView, UIWindow. As you know, it is a little weird that UIWindow is subclass of UIView, while on the Mac it is opposite.
How to understand this? On a Mac, it is like that view is the region of scene you can see through a window. So, the window provides a view. So, NSView
is a subclass of is located under the NSWindow in its hierarchy. However, for iPhone, view is the whole scene which is outside of a window. Very wide seashore, very tall and wide mountain, open crop field, and so on. They are the view. However, window restrict how much you can see the view or whole scene. So, the window class is a subclass of the view class.
Well, things can be different how we see the world! :)