Re: Overriding -[UIViewController loadView], and loading from a nib
Re: Overriding -[UIViewController loadView], and loading from a nib
- Subject: Re: Overriding -[UIViewController loadView], and loading from a nib
- From: Jonathan del Strother <email@hidden>
- Date: Tue, 3 Nov 2009 17:20:47 +0000
Sorry - I'm not following. What did you mean by hooking up IB to
auto-load the nib?
2009/11/3 Luke the Hiesterman <email@hidden>:
> You should pick one place or the other to do your nib loading. If you choose
> to do it yourself, then don't hook up IB to automatically load the view
> controller's nib. Then you can safely call [super loadview] followed by your
> own code which includes loading the view from the nib. Alternatively,
> continue to have hook-ups to automatically load from the nib, and then in
> your own loadview, only do custom stuff that doesn't touch the nib.
>
> Luke
>
> On Nov 3, 2009, at 5:27 AM, Jonathan del Strother wrote:
>
>> 2009/11/3 Jonathan del Strother <email@hidden>:
>>>
>>> Heya,
>>>
>>> I'd like to get hold of the top level objects returned by -[NSBundle
>>> loadNibNamed:owner:options:] when UIViewController loads my view.
>>> Sadly UIViewController doesn't seem to provide any way of accessing
>>> these, so I thought I might be able to just load the nib myself :
>>>
>>> -(void)loadView {
>>> NSArray* topLevelObjects = [self.nibBundle
>>> loadNibNamed:self.nibName
>>> owner:self options:nil];
>>> // do stuff with topLevelObjects...
>>> }
>>>
>>> which appeared to work pretty well, until I tried using it in a
>>> UITableViewController subclass that's pushed onto a navigation
>>> controller, where the view just turns out blank. Stepping into
>>> -[UIViewController loadView] in gdb suggests that it's doing a whole
>>> lot more than just -loadNibNamed:
>>>
>>> I could call [super loadView], but that means I end up loading the nib
>>> twice, and re-assigning all the IBOutlets twice, which is pretty ugly.
>>> Any alternative suggestions?
>>>
>>
>>
>> Just as a follow up - it finally twigged that my tableview delegate &
>> datasource weren't hooked up in the nib. Looks like
>> -[UITableViewController loadView] automatically sets them if they're
>> weren't already. Connecting those up has fixed my blank view issue.
>>
>> Even so, I wonder what else I'm missing by not calling [super
>> loadView]. Seems a pretty fragile approach...
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden