Create a custom class subclassing UITableViewCell. Make sure to check the nib check box.
Add desired controls on the nib and link them with outlets.
Method 1:
- Set identifier of table view cell object in Interface Builder to the identifier, that is to be used in code to make object of cells.
- Write following code in cellForRowAtIndexPath method:
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@”iCodeBlogCustomCell” owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[CustomCell class]])
{
cell = (CustomCell *)currentObject;
break;
}
}
}
Method 2:
- Create a custom init method in custom cell view class with following code:
- (id)init
{
self = [[[[NSBundle mainBundle] loadNibNamed:@"NibName" owner:self options:nil] objectAtIndex:0] retain];
if (self)
{
// any further initialization
}
return self;
}
- Write following code in cellForRowAtIndexPath method:
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[[CustomCell alloc] init] autorelease];
}
// setup your cell
return cell;
Do let me know if none of the above works for you.