`

UITableView小片段,小总结

阅读更多

1.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

方法要比

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法

先返回

 

即,高度比cell填充先返回

 

2.

xib自定义Cell,复用无效;需要用代码重写

 

再一次验证,xib自定义的Cell可以复用

有两种方式,

第一种:

     在自定义的Cell里面重写reuseIdentifier方法

- (NSString*)reuseIdentifier
{
    //返回的是在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;方法里定义的reuseIdentifier
    return @"ContentCELL";
}

 第二种:

在cell的xib文件里定义

 

我又测试了几遍,发现iOS不靠谱呀,有时候可以复用,有时候不可以

但解决的方式应该就有这两种

 

  • 大小: 25.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics