Question about _headerView property


#1

Hi,

I’m reading 289 pages, and I don’t understand how _headerView could be valued.

@property (nonatomic, strong) IBOutlet UIView *headerView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kCellIdentifier];
    
    UIView *header = self.headerView;
    [self.tableView setTableHeaderView:header];
}

- (UIView *)headerView
{
    if ( !_headerView ) {
        [[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];
    }
    return _headerView;
}

In above, I don’t see _headerView get to be assigned directly, but actually, when I track it via debugger, _headerView gets pointer after the bundle load.

Could someone explain why _headerView gets a pointer of the view after loading the nib bundle, please?


#2

You set up headerView outlet that references the HeaderView.xib on page 182.

At this point in the exercise, we are manually loading the nib. Initially, (before the nib has loaded) _headerView will be nil.

After the nib has been loaded the first time (from the first call to the headerView method), the outlet we set up on page 182 means that _headerView will now point to the HeaderView.xib.


#3

Got it.

Thank you for the explanation.

[quote=“codeartisan”]You set up headerView outlet that references the HeaderView.xib on page 182.

At this point in the exercise, we are manually loading the nib. Initially, (before the nib has loaded) _headerView will be nil.

After the nib has been loaded the first time (from the first call to the headerView method), the outlet we set up on page 182 means that _headerView will now point to the HeaderView.xib.[/quote]