loadNibNamed: query


#1

I’m trying to add a little more to the footer view (in addition to the header view in the example project. Specifically some labels that I can update from the view controller.

This is where I’m running into some problems. If I declare an IBOutlet and update the value of it within the footerView method for instance [myLabelField setText:@“some text”];
It works fine. If I try to update the label from viewDidLoad it’s not working.

Is it just to do with the order of the methods. For instance, is the footerView method being called AFTER viewDidLoad and therefore that’s why it’s not updating?

Also I’ve got what is probably a silly question.

In the footerView method, it’s returning the footerView object which is declared in the view controllers header file.

Why does the code to load the XIB file not require an assignment?

Basically how does this:

[code] if(!footerView)
{
//Load the xib file
[[NSBundle mainBundle] loadNibNamed:@“FooterView” owner:self options:nil];

}[/code]

translate as this:

Is it a side effect of the if statement to return a value of footerView? I can’t understand how else footerView is assigned to the result of the NSBundle method.

Thanks to anyone that can shed light on it! :slight_smile:


#2

For your first question, at the time of viewDidLoad, only the ItemsViewController’s view has been loaded. The footer view is only loaded when the system calls either tableView:viewForFooterInSection: or tableView:heightForFooterInSection:, provided you are calling [self footerView] in those implementations - you can check this by adding an NSLog to your footerView method.

For your second question, the footerView variable should have been specified as an IBOutlet and connected to the footer view in the xib - that is how, when the nib is loaded, the footerView member variable is set based on that IBOutlet connection.

HTH,
Anand