How to add a custom subview to a UITableViewCell derived class when the UITableViewCell is loaded using loadNIB

I am trying to add a custom view control to a custom UITableViewCell which I had designed in the interface builder.

Now, to load UITableCellView I am using

NSArray * loadedViews = [[NSBundle mainBundle] loadNibNamed:@"CustomSearchResultsCell" owner:self options:nil];

What method of the CustomSearchResultsCell class will be called the Nib loads the view and initializes it. I tried using viewDidLoad, but UITableViewCell does not respond to this method. Also initWithStyle is not being called in this case.

TIA Nitin

-------------Problems Reply------------

Views loaded from a nib are initialized with initWithCoder:, which you can implement in a similar way like initWithFrame:.

Also, take a look at Apple' Sample Code called AdvancedTableViewCells. In this example they use following code to load table view cell from XIB:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"ApplicationCell";

ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

[[NSBundle mainBundle] loadNibNamed:@"IndividualSubviewsBasedApplicationCell" owner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;

return cell;

Category:iphone Views:1 Time:2010-03-07

Related post

Copyright (C), All Rights Reserved.

processed in 0.130 (s). 11 q(s)