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
cellForRowAtIndexPathI see[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: theTestController options:nil]; instead? -
What is the difference between
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: theTestController options:nil];andtheTestController = [[[CustomCell alloc]initWithNibName:@"CustomCell" bundle:[NSBundle mainBundle]]autorelease]; -
I tried replacing
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: theTestController options:nil];withtheTestController = [[[CustomCell alloc]initWithNibName:@"CustomCell" bundle:[NSBundle mainBundle]]autorelease];and I got errors. Looks like the outlets remainnilif I use the latter.
initWithNibName:bundle:is convenience method declared inUIViewControllerand is available to its subclasses. This will initialize the view controller by loading the nib, probably by usingloadNibName:owner:options:method internally.initWithNibName:bundle:is unavailable toUIViewand its subclasses. So we have to make use ofloadNibName:owner:options:to load views.UIViewsubclasses and hence make use ofloadNibName:owner:options:.initWithNibName:bundle:is a convenience method forUIViewControllerinitialization.