哈02—kill error_______unable to dequeue a cell with identifier Cell

使用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'

意思:带有标记的cell,没有经过注册nib、class或是连接到storyboard的特定cell,不能够被重用

终于下决心把它把它封杀

错误的原因一般有以下:

  编译设备的系统低于6.0

未使用配套方法

系统里有以下方法

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;  

// 通过委托调用来获取一个新的cell代替已被分配使用的cell(Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one)

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPathNS_AVAILABLE_IOS(6_0);

//(这是新的一个重用cell的方法,该方法通过注册可重用标记,来保证cell的可返回及重置大小) newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered

该方法必须配套使用

- (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifierNS_AVAILABLE_IOS(6_0); // like dequeueReusableCellWithIdentifier:, but for headers/footers

// Beginning in iOS 6, clients can register a nib or class for each cell.

// If all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned.

// Instances returned from the new dequeue method will also be properly sized when they are returned.

(从ios6开始,客户端可以为每个cell注册一个可重用标记,如果所有的可重用标记都被注册,就根据版本情况配套以下方法使用新方法)

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifierNS_AVAILABLE_IOS(5_0);

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifierNS_AVAILABLE_IOS(6_0);


- (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifierNS_AVAILABLE_IOS(6_0);

- (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifierNS_AVAILABLE_IOS(6_0);

例如:

  1.  //6.0之前的用法  
  2.     /* 
  3.     static NSString *CellIdentifier = @"Cell"; 
  4.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
  5.      
  6.     if (cell == nil) { 
  7.         cell.textLabel.text = [NSString stringWithFormat:@"5.0方法 %d", indexPath.row]; 
  8.     }*/
  1. //新方法
    1. [self.notNib_tableView registerClass:[MXCustomCell class] forCellReuseIdentifier:CellIdentifier];  
    2.     self.notNib_tableView.dataSource = self;  
    3.     self.notNib_tableView.delegate = self;  
    4.     [self.view addSubview:self.notNib_tableView];  
     
  2.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier  
  3.                                                             forIndexPath:indexPath];  
  4.     //这里做一些cell属性变换,如:  
  5.     cell.textLabel.text = [NSString stringWithFormat:@"6.0方法 %d", indexPath.row];  
  6.     return cell;  


如果写的还可以可以给楼主一点鼓励,有利于该小白茁壮成长


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值