今天在做UITableView 的时候,又遇到Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'的异常。这是第二次遇到借助上一次的经验发现由于SDK版本的问题
-
(id)dequeueReusableCellWithIdentifier:(NSString
*)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
在某些情况下会有问题.解决的方法是
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=@"Cell";
//添加解决问题的核心代码
[self.tableViewregisterClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell==nil){
cell =[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
}
NSUInteger row = [indexPathrow];
cell.textLabel.text = [_nsArrayobjectAtIndex:row];
return cell;
}
关键是要把这个Cell这个类注册一下。然后问题就ok