TableViewCell 复用解决

来源:互联网 发布:重庆行知教育集团 编辑:程序博客网 时间:2024/04/30 11:31

在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

0 0
原创粉丝点击