Frage

I followed this UITabBarController Tutorial which creates a Tab Bar with according subviews mostly using Interface Builder. The UITabBarController is created there and the Tab's View Controllers are added there too.

Am I correct that creating the UIViewControllers {WelcomeViewController|AboutViewController}.{h|m} is unnecessary?

Who is the real File's Owner of the Subviews {WelcomeViewController|AboutViewController}.xib?

Note that I at first tried to create an IBAction method in WelcomeViewController.h: in Interface Builder at WelcomeViewController.xib, I could connect a button press to that action as it appeared at File's Owner. But at runtime it crashed, as the real File's Owner presumably is not an Object of WelcomeViewController.m. Am I right here? Is it a bug that the IBAction appears in Interface Builder (Xcode 4 here)?

A last question: How/can I still separate code (having IBActions in WelcomeViewController.h for actions that happen only on this subview) when I connect everything up in Interface Builder like in the tutorial?

War es hilfreich?

Lösung

Am I correct that creating the UIViewControllers {WelcomeViewController|AboutViewController}.{h|m} is unnecessary?

No, both controllers are necessary, since there should be at least (and, optimally, at most) one ViewController per full-screen window to manage your view hierarchy. The TabBarController is only a kind of "dumb" meta-controller managing the display of the sub-controllers it loads - therefore you need controllers for the views which are switched. I would recommend you read this part of the Apple doc.

Who is the real File's Owner of the Subviews {WelcomeViewController|AboutViewController}.xib?

The File's Owner should be the corresponding controller class (in your case, {WelcomeViewController|AboutViewController}.{h|m}) - you can set the class in Interface Builder in the inspector palette when File's Owner is selected. Only the very first window (usually called Main.xib or so) which is opened at application start should have the application delegate as File's Owner. File's Owners own the objects of the XIB/NIB file - object-reference wise, you know what I mean :) I think it should also be possible to load the XIB/NIB file with other controllers (and the other controller automatically becoming the File's Owner), but I'm not sure.

... Am I right here? Is it a bug that the IBAction appears in Interface Builder (Xcode 4 here)?

It may be that you wired up the action the wrong way in Interface Builder, a common mistake. Try holding the Ctrl key, then drag a line from the button onto the File's Owner, and choose the desired method to link to. That should do it.

A last question: How/can I still separate code (having IBActions in WelcomeViewController.h for actions that happen only on this subview) when I connect everything up in Interface Builder like in the tutorial?

I think I answered this in the first paragraph - WelcomeViewController is still there and all you have to do is create IBOutlets and wire them up in IB. Of course, you can also do the wiring programmatically, since the member "view" is automatically populated (via the File's Owner connection), and all subviews are accessible from there.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top