coffeemonitor
coffeemonitor

Reputation: 13120

xcode 4.2 iphone ViewController.xib and MainWindow.xib

I'm confused about the differences between the ViewController.xib and MainWindow.xib.

All tutorials, and books seems to be referencing the MainWindow.xib, quite consistently. However, when I select any template from xcode, I don't see it.

I do sometimes see ViewController.xib premade, for certain templates. But still, MainWindow.xib doesn't appear to be created.

This confuses me. Is MainWindow.xib important? Why are many teaching resources referencing this MainWindow.xib file, but not the reason it isn't created? Is it my version of xcode?

Upvotes: 0

Views: 1762

Answers (1)

i300
i300

Reputation: 116

MainWindow.xib is created with most of the included xCode 4.2 templates. It simply contains a UIWindow in a .xib which is used by the App Delegate. UIWindow is the window which your app is contained in.

The difference between MainWindow.xib and ViewController.xib are big, and little. You could choose to your entire application UI in MainWindow.xib. This would mean you only need one view for your entire app. If you chose to layout your application in ViewController.xib, you might need one or many views. The big difference between MainWindow.xib and ViewController.xib is that ViewController.xib is the View part of the Model View Controller (or MVC) pattern.

Definition of MVC from Wikipedia:

Model View Controller (MVC) pattern creates applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

The ViewController.xib contains a UIView that will be controlled by a UIViewController. The UIViewController class lets you easily handle a view, knowing when events such as the view loading and unloading occur. The UIWindow in MainWindow.xib is hooked up to an App Delegate which only knows information about the Application launching, and other application-specific events.

If you chose to, you could modfity the MainWindow.xib to include a UIView to be handled by a separate UIViewController.

Upvotes: 1

Related Questions