在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-];
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-];
}
};
return cell;
}
參考的博文内容來自
http://www.itnose.net/detail/6154013.html