- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
works perfect with ios 6 simulator but crash on ios 5 simulator with the following error: 'NSInternalInconsistencyException', reason: 'The NIB data is invalid.
did apple changed something?
Here are some suggestions!
If you created this project with a recent version of Xcode (Xcode 4.5 or 4.6), the CustomCell nib has autolayout turned on by default. But there is no autolayout in iOS 5.
Also your code is wrong in both iOS 5 and iOS 6. If you're getting your cell from a nib, do not use loadNibNamed:
. Instead, register the nib with the table view, with registerNib:forCellReuseIdentifier:
. Now when you call dequeueReusableCellWithIdentifier:
the nib will be loaded automatically if necessary. Note that there must be only one top-level object in this nib, and it must be the cell. It's a dumb rule, but that's how it is.