iOS: Load custom UITableViewCell with Nib

On March 2, 2014, in Coding, iOS, by Dipin Krishna

Using the interface builder i created a custom ‘UITableViewCell’ named ‘MyCustomCellNib’, with a
custom class file ‘MyCustomCell’ inherited from ‘UITableViewCell’.

This is code i used to load the cell with the nib.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyCustomCell *cell = (MyCustomCell *) [tableView dequeueReusableCellWithIdentifier:@"MyCustomCellIdentifier"];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCellNib" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
	// cell is a 'MyCustomCell' object.
    return cell;

Hope it helps! 🙂

Tagged with:  

Leave a Reply