美文网首页IOS
UITableView dequeReusableCellXXX

UITableView dequeReusableCellXXX

作者: 陈鸿禧 | 来源:发表于2016-04-13 23:02 被阅读70次

UITableView 获取可重用Cell有以下两个方法
[tableView dequeueReusableCellWithIdentifier:ID] [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath]

官方建议使用dequeueReusableCellWithIdentifier: forIndexPath

因为它会检查storyboard中的Cell是否填了reuseIdentifier,没有则会崩溃给你看😓,那个IndexPath其实没个卵用。

storyboard中的Cell只要填了reuseIdentifier,这两个方法是等价的

storyboard中注册了cell后,不需要再判断 cell == nil

XXXCell *cell = [self.tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath] // if (cell == nil){ // cell = [[XXXCell alloc] initWithStyle:XX resueIdentifier:ID]; // } return cell

注册Cell的三个方法

1.storyboard 填写
2.[self.tableView registerClass:class forCellReuseIdentifier:identifier];
3.[self.tableView registerNib:nil forCellReuseIdentifier:identifier];

相关文章

网友评论

    本文标题:UITableView dequeReusableCellXXX

    本文链接:https://www.haomeiwen.com/subject/smkglttx.html