I have created a .xib file which has more than 2 tableview cells. I used the following code in the viewDidLoad() method for registering nib to reuse cells.
UINib *nib = [UINib nibWithNibName:@"CartTableViewCells" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"Cell0"];
[self.tableView registerNib:nib forCellReuseIdentifier:@"Cell1"];
[self.tableView registerNib:nib forCellReuseIdentifier:@"Cell2"];
And In - [UITableView CellForRowAtIndexPath] method, I used the following code.
cell0 = (CartTableViewCells *)[self.tableView dequeueReusableCellWithIdentifier:@"Cell0"];
if (cell0==nil)
{
cell0 = [[[NSBundle mainBundle] loadNibNamed:@"CartTableViewCells" owner:self options:nil] objectAtIndex:0];
}
But My app crashed with the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (Cell0) - nib must contain exactly one top level object which must be a UITableViewCell instance'
[[NSBundle mainBundle] loadNibNamed: owner: options:]this returns an array, i don't know if you would have each cell on diff position of the array. Something like this :NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"mynib" owner:self options:nil]; UINib *nib = [nibs objectAtIndex:0] [self.tableView registerNib:nib forCellReuseIdentifier:@"Cell0"];You have to do the same for the rest of the nibs on the array - Lucho