Reputation: 33050
theTestController = [[[CustomCell alloc]initWithNibName:@"CustomCell" bundle:[NSBundle mainBundle]]autorelease];
My guess is that it will load CustomCell and set theTestController as the owner. If so:
Why in most sample code for cellForRowAtIndexPath
I see [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: theTestController options:nil]
; instead?
What is the difference between [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: theTestController options:nil];
and theTestController = [[[CustomCell alloc]initWithNibName:@"CustomCell" bundle:[NSBundle mainBundle]]autorelease];
I tried replacing [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: theTestController options:nil];
with theTestController = [[[CustomCell alloc]initWithNibName:@"CustomCell" bundle:[NSBundle mainBundle]]autorelease];
and I got errors. Looks like the outlets remain nil
if I use the latter.
Upvotes: 2
Views: 2645
Reputation: 44633
initWithNibName:bundle:
is convenience method declared in UIViewController
and is available to its subclasses. This will initialize the view controller by loading the nib, probably by using loadNibName:owner:options:
method internally.
initWithNibName:bundle:
is unavailable to UIView
and its subclasses. So we have to make use of loadNibName:owner:options:
to load views.
UIView
subclasses and hence make use of loadNibName:owner:options:
.initWithNibName:bundle:
is a convenience method for UIViewController
initialization.Upvotes: 6