Reputation: 1104
I know that UIViewController's designated initializer is
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
If you call init
,according to the documentation it will load the class's same name nib file(if it exist).
But what I encounterd is that sometimes init does do everything right. But sometimes some UIViewController's subclass 's init method just don't load it's nib file. I create them using the same way(using Xcode's assistant to create a UIViewController subclass and it's associated nib file at the same time, so the file name should all be the same).
Why is this happening?
Upvotes: 1
Views: 546
Reputation: 1104
I figure out that if the class is UITableViewController's subclass, you must use - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
to init from nib.
This is because UIViewController's designate initializer is:
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
so if you use init
,it would therefore call (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
for you.
But UITableViewController's designate initializer is:
- (id)initWithStyle:(UITableViewStyle)style
using init
on UITableViewController will call initWithStyle
not initWithNibName
Upvotes: 1