您的位置:首页 > 其它

TableViewCell 复用解决

2016-06-14 14:02 190 查看
在Storyboard中 的tableViewCell每个cell包含了一个播放器。有时会出现复用的情况。针对此种情况做以下修改——————- 将cell写入Xib,解决了重复显示的问题。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

// 定义唯一标识
NSString *CellIdentifier = [NSString stringWithFormat:@"AudioListCell%ld%ld",indexPath.section,indexPath.row];
// 通过indexPath创建cell实例 每一个cell都是单独的
AudioListCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// 判断为空进行初始化  --(当拉动页面显示超过主页面内容的时候就会重用之前的cell,而不会再次初始化)
if (!cell) {
UINib* nib = [UINib nibWithNibName:@"AudioListCell" bundle:[NSBundle mainBundle]];
[tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
AudioFileInfoModel *fileInfo = self.dataArray[self.dataArray.count-indexPath.row-1];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (!cell.isInit) {
[cell setValueWithfileInfo:fileInfo];
cell.isInit = YES;

}
__weak __typeof(&*self)weakSelf = self;
cell.delegate = weakSelf;

cell.reuploderBlock = ^(BOOL reuploderOrNot){
if (reuploderOrNot) {

[weakSelf.auidoCachesManager re_uploadFile:fileInfo andInteger:weakSelf.dataArray.count-indexPath.row-1];
}
};

return cell;
}


参考的博文内容来自

http://www.itnose.net/detail/6154013.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: