您的位置:首页 > 产品设计 > UI/UE

TableView unable to dequeue a cell with identifier Cell - must register a class or Nib

2014-09-06 09:53 375 查看
最近一直在学习UIKit 框架,里面的功能真的是很强大,所以决定尝试了 一下tableViewController 。

可是遇到了很多问题。

BUG:TableView unable to dequeue a cell with identifier Cell - must register a class or Nib

BUG大概是在告诉我们UITableVIew并没有注册一个类,或者说我们找不到这样一个UItableView。

那我们来看一下registerclass

我们来看看官方的注释

1 // Beginning
in iOS 6, clients can register a nib or class for each cell. 2 // If
all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned. 3 // Instances
returned from the new dequeue method will also be properly sized when they are returned. 4 -
(void)registerNib:(UINib
*)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0); 5 -
(void)registerClass:(Class)cellClass
forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

大致的译文:我们可以为每个cell 注册nib 或类,如果所有的复用Identifiers都注册过了,可以尝试一下新的方法dequeueReusableCellWithIdentifier:forIndexPath: ,确保每一个cell都被返回。

看来我们一定要给tableView注册了。

我在ViewDidLoad里面为tableView加了一句

[self.tableView registerClass[UITableVIewCell Class]forCellReuseIdentifier:@"SimpleTable"];//这里的ReuseIdentifier
一定要跟代理方法里的保持一致,不然还是找不到你的UITableVIewCell.

运行一下,问题果然解决了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐