Rendy
Rendy

Reputation: 5698

Connected IBOutlet component null?

I have following code with following xib:

@property (nonatomic, retain) IBOutlet UITableViewCell *cellLoadMore;

enter image description here

When I try to NSLog the cellLoadMore, it returns null, however, when I try to NSLog the view, it has value. What could be the problem of cellLoadMore returns null?

Below is my code:

- (void)viewDidLoad{
  [super viewDidLoad];

  NSLog(@"cell load more %@", cellLoadMore_);
  NSLog(@"view %@", self.view);
}

Console prints:

cell load more (null)
view <UITableView: 0x1284200; frame = (0 20; 320 460); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xa393b0>; contentOffset: {0, 0}>

Note: My class is a subclass from UITableView.

Upvotes: 0

Views: 918

Answers (3)

Rendy
Rendy

Reputation: 5698

I faced this problem some times and managed to solve it by change my controller from subclass of UITableViewController into UIViewController that using UITableview delegate. This is quite annoying though.

Upvotes: 0

borrrden
borrrden

Reputation: 33421

I think this is what is happening. You are making a property, and an instance variable, but you are not synthesizing the property correctly. By default on Xcode 4.4+ the property will be synthesized to _cellLoadMore and not cellLoadMore_. On older versions, if you use simply @synthesize cellLoadMore then the variable will be cellLoadMore. So basically, if you don't have a line that says @synthesize cellLoadMore = cellLoadMore_, then you have two different variables.

Upvotes: 1

jimpic
jimpic

Reputation: 5520

You are probably "logging" before the cell is loaded. The cell will be loaded the first time it is really used (google for "lazy loading"). If you access the view of the cell, it is really used and therefore really loaded. You can log the view and the cell after that and it shouldn't be null anymore.

Upvotes: 0

Related Questions