Tejas Chauhan Tejas Chauhan - 1 year ago 81
Objective-C Question

How to add a custom UITableViewCell to a xib file objective-c

I want to load my custom xib for tableviewcell in view controller.I can't load my xib in tableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:[CustomCell reuseIdentifier]];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = _customCell;
_customCell = nil;

cell.topLabel.text = @"I am on top";
cell.bottomLabel.text = @"and I'm on the bottom";

return cell;

I cant't load my custom cell from xib into tableview.
Please help me.


You can do like this in Tableview cellforrowAtIndexPath methods,

static NSString *CellIdentifier = @"CellData";

NSArray *arrData = [[NSBundle mainBundle]loadNibNamed:@"cellTaskDetail" owner:nil options:nil];

cellTaskDetail *cell = [[cellTaskDetail alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell = [arrData objectAtIndex:0];

return cell;

Its work fine...do it