是什麼讓UITableView上的滾動變得如此波濤洶涌?在我看來,下面的代碼是一個罪魁禍首。我很難用其他的東西代替這個邏輯。UITableView由於removeFromSuperview而不能平滑滾動
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview]; }
這就是我正在做的。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
BGMArticleAbstract *articleAbstract = [self.section.articleAbstracts objectAtIndex:indexPath.row];
[cell.contentView addSubview:[self getHedlineFromArticleAbstract:articleAbstract]];
[cell.contentView addSubview:[self getThumbnailImageFromArticleAbstract:articleAbstract]];
[cell.contentView addSubview:[self getAbstractParaFromArticleAbstract:articleAbstract]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell; }
我在做,因爲我正在創建一個動態單元格高度,因此將contentSubview添加到contentview。有什麼辦法可以使這個滾動視圖工作順利嗎?感謝您的幫助。
您是否嘗試過不重新加載單元格?這樣每次都會給你一個乾淨的標準,每當生成一個新的單元時,你就不必從cell.contentView中刪除所有的子視圖。 – Echihl