Apple's AdvancedTableViewCells Question
I'm looking at Apple's "AdvancedTableViewCells" sample project, and in looking at the RootViewController
, I noticed the nib loading for the IndividualSubviewsBasedApplicationCell
. I was wondering about that nib loading... what is it loading into? There is no handle/variable. I understand the lines below where cell is assigned to the view via the IBOutlet
, but I don't understand the line: [[NSBundle mainBundle] loadNibNamed:@"IndividualSubviews开发者_如何学PythonBasedApplicationCell" owner:self options:nil];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
#if USE_INDIVIDUAL_SUBVIEWS_CELL
[[NSBundle mainBundle] loadNibNamed:@"IndividualSubviewsBasedApplicationCell" owner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
See Jeff LaMarche's article Table View Cells in Interface Builder - the Apple Way™.
In the NIB file IndividualSubviewsBasedApplicationCell
, "File's Owner" is set to RootViewController
, and the custom UITableViewCell
is connected to the tmpCell
IBOutlet
of RootViewController
.
In the line:
[[NSBundle mainBundle] loadNibNamed:@"IndividualSubviewsBasedApplicationCell" owner:self options:nil];
...the bundle loader loads the NIB file and connects all the outlets. Once it has done this, the tmpCell
IBOutlet
now points to our custom UITableViewCell
.
精彩评论