Hey guys, I just joined the forum, looks like you have a good community going here. I have been a (java/php) web developer for several years, and even have a year of webobjects development under my belt, and I'm really anxious to get started on iphone app dev. (Any other webobjects veterans here?)
Anyway, on to my question.
I have been playing around with all the sample code for a few weeks now, and have started building my first app, (the framework anyway...) but i have a question about how the interface builder nibs/xibs tie into the c-code. I see that when a NIB is loaded, the awakeFromNIB and initWithCoder methods are called (messages sent) but I don't see what it is in the framework that autoloads the NIBs.
I have a class named MasterViewController that will be responsible for switching between a variety of different view controllers. In the MainWindow.xib I created an interface object with the same name, with the MasterViewController as its class. I created an outlet in the app-delegate class for the MasterViewController (and connected in interface builder) and that seems to be enough to cause the MasterViewController.xib to be autoloaded. The problem comes at the next level, when i attempt to load the first view controller being managed by the MasterViewController. I created an interface object for the other ViewController (lets just call it OtherViewController) and an outlet for it in the MasterViewController, but when I try to reference it in code, OtherViewController.xib isn't being autoloaded. I noticed however, if i create a dummy view for OtherViewController in the MasterViewController.xib, and tie it to the outlet of the view for MasterViewController, the OtherViewController.xib IS being loaded. So let me just say that again: If i tie an outlet of the Master to the Other as a view controller, it won't autoload the NIB, but if i tie the view outlet of the master to the view of the OtherViewController it will.
Is there something magical about the view message being sent that causes the NIB to load, while the other get messages won't?
I know that I said quite a mouthful there... but If you were able to follow all that, is there something I'm missing here? And feel free to tell me "you're doing it wrong" if i'm totally off base with this whole MasterViewController thing, and I should be doing the ViewController swapping in the delegate. I'm not sure what the 'correct' way to do it is, and the sample code from apple seems to use several different schemes of organization.
I'd be happy to provide more detail if what i described above isn't sufficient. Thanks in advance!
Your main nib is loaded when the app begins because its name is specified in the Info.plist file. You can see this in the targets settings window in the Properties tab under Main Nib File. This is set up automatically when you build the project from a template.
Your life will be simpler if you use a navigation controller. Use a navbar. Write a navbar app for your first app. It is simpler to understand and will work better.
In most cases nibs are loaded in response to initWithNibName:bundle: Just declaring an IBOutlet doesn't make the nib load.
Your main nib is loaded when the app begins because its name is specified in the Info.plist file. You can see this in the targets settings window in the Properties tab under Main Nib File. This is set up automatically when you build the project from a template.
Your life will be simpler if you use a navigation controller. Use a navbar. Write a navbar app for your first app. It is simpler to understand and will work better.
In most cases nibs are loaded in response to initWithNibName:bundle: Just declaring an IBOutlet doesn't make the nib load.
Yep, i noticed how the .plist files calls out the MainWindow.xib earlier. I looked into the NavigationController, and it is accomplishing almost exactly what I need, but I don't think it will work for me. I'm trying to avoid having the apple visual items in my app, and i didn't see any way to get rid of the title bar at the top of the screen. Is there a way to do this?
What i was getting at in my question, is that i don't understand why certain outlets (the view outlet) when called from code will autoload the NIB, but the otherViewController outlet that i created did not, when called from the code in exactly the same way.
[masterViewController view] or masterViewController.view will both trigger the loading of the OtherViewController.xib, but [masterViewController otherViewController] or masterViewController.otherViewController does not.
You can set the statusbar to hidden. Be aware that your screen geometry will change ( from 460 to 480 pixels).
Apart from the nib file specified in the .plist file no other nibs are autoloaded. You have to do that in code (and it also makes sense as it gives you the flexibility to only load them when you actually need to display them)
There is a way for one nib to reference another nib so that the second nib is automatically loaded when the first is loaded. The navbar template is set up this way. There's a MainWindow.nib and a RootViewController.nib and the main nib references the rootview nib and both are loaded when the app starts.
Regarding the app controller, it is possible to make the navbar hidden and still use the nav controller to manage the appearance of views and their view controllers. Alternatively you could use a tabbarcontroller. If you don't use either of these you will be duplicating their functionality in some way. I won't say you can't do an app without one or other of these classes. I will say that for your first app you will have problems figuring out how to duplicate their functionality, rather than working on the interesting parts of your app.
You can set the statusbar to hidden. Be aware that your screen geometry will change ( from 460 to 480 pixels).
Apart from the nib file specified in the .plist file no other nibs are autoloaded. You have to do that in code (and it also makes sense as it gives you the flexibility to only load them when you actually need to display them)
Hiding the bar won't work, i need that real estate!
I'm pretty sure that when i call [viewController view] from the app delegate, it is loading the secondary .xib - I tried painting the background color yellow for the view in interface builder, and it launched with the yellow screen. I also set breakpoints in the awakeFromNIB and initFromCoder methods and they were hit too.
[viewcontroller view] or viewcontroller.view returns the view property of the viewcontroller. If it wasn't already loaded in from the nib, or had been unloaded, it is loaded from the nib and then returned.
There is a way for one nib to reference another nib so that the second nib is automatically loaded when the first is loaded. The navbar template is set up this way. There's a MainWindow.nib and a RootViewController.nib and the main nib references the rootview nib and both are loaded when the app starts.
Regarding the app controller, it is possible to make the navbar hidden and still use the nav controller to manage the appearance of views and their view controllers. Alternatively you could use a tabbarcontroller. If you don't use either of these you will be duplicating their functionality in some way. I won't say you can't do an app without one or other of these classes. I will say that for your first app you will have problems figuring out how to duplicate their functionality, rather than working on the interesting parts of your app.
Daisy chaining sounds like an interesting option, but i'd be concerned about the memory implications.
I hear what you're saying about the tab and nav controllers, but won't i spent a lot more effort just getting rid of all of the nav/tab elements? The requirements for my app include full screen views w/o the navigation elements - is this easy to rig up with the existing controllers?
I'm starting to get the feeling that whatever this whole auto-loading thing is, it doesn't sound like something that anyone who replied here counts on, and that manual NIB loading is the rule, not the exception.
[viewcontroller view] or viewcontroller.view returns the view property of the viewcontroller. If it wasn't already loaded in from the nib, or had been unloaded, it is loaded from the nib and then returned.
Right, my question was why viewcontroller.view loads the NIB, but viewcontroller.otherviewcontroller doesn't load the NIB. However, it is starting to seem like to me, that i may just want to stick to the manual loading.
What you're calling autoloading is just the chaining of references from the main nib to other dependent nibs. Too much memory usage is always a concern so in my code I don't create view controllers unless they're about to be used and I release them when they're done. I think that would be the common pattern. So I don't chain all the view controllers so the main nib depends on them.
The view controller and its main view, which comes from its nib, are separate objects, although closely related of course. When you alloc/init a view controller its view isn't loaded yet. The nib is loaded (shortly) later when the view property is requested when some code adds the view controller's view to the view hierarchy that runs to the app window. This usually happens by a nav controller or tab bar controller but you can do it manually if you wish.
So, viewcontroller.otherviewcontroller refers to the view controller and viewcontroller.view refers to the view and loads it from the nib if required. OtherviewController's nib is loaded when its view property is requested (by some code).
Regarding hiding the navbar, it's a checkbox in IB to set it to hidden.
So, viewcontroller.otherviewcontroller refers to the view controller and viewcontroller.view refers to the view and loads it from the nib if required. OtherviewController's nib is loaded when its view property is requested (by some code).
Yes, I understand that well, but what i don't understand is why the NIB isn't being loaded when i call for the view controller class that it represents. It's probably a moot point, as i plan on manually loading; or using, as you suggest, the navigation controller.
I'm using this method. My problem is that after it flips the screen I never see the nib load. I get the status bar up top but under that is what remains of the previous screen. What am I doing wrong?