【发布时间】:2014-04-29 23:26:10
【问题描述】:
我有一个自定义表格视图和单元格,其中一个单元格在选中时会展开。它现在可以正常运行并相应地运行。但是,当我选择单元格来展开它们时,大约需要半秒钟才能做出响应。下面的代码位于 didSelectRowAtIndexPath 中。 我的假设是在 beginUpdates 和 endUpdates 之间,有太多的事情要增加原始单元格的高度,然后更新整个表格视图。还有其他方法可以更好地实现吗?
**[_tableView beginUpdates];**
ReviewTestTableCell *reviewCell1 = (ReviewTestTableCell *)[tableView cellForRowAtIndexPath:indexPath];
CGRect rect = CGRectMake(reviewCell1.review.width, 900, reviewCell1.review.width, 900);
CGRect textRectb = [reviewCell1.review textRectForBounds:rect limitedToNumberOfLines:1000];
float labelHeight = textRectb.size.height;
reviewCell1.review.height = labelHeight;
expandHeight = labelHeight + 75 ;
if ([[userdefaults objectForKey:@"merchantType"] isEqual:@"T"])
{reviewCell1.height = labelHeight + 50;
reviewCell1.bottomRatingView.height = reviewCell1.bottomRatingView.height - 20;
}
else
{
reviewCell1.height = labelHeight + 75;}
reviewCell1.bottomRatingView.hidden = NO;
reviewCell1.bottomRatingView.top = reviewCell1.review.bottom;
**[_tableView endUpdates];**
[_isExpandList replaceObjectAtIndex:indexPath.row withObject:@1];
}
编辑/添加:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell3 = [self tableView:tableView cellForRowAtIndexPath:indexPath];
if ([_isExpandList[indexPath.row] isEqual: @1] && [[_dataList objectAtIndex:indexPath.row] valueForKey:@"Item1Score"] != nil) {
return cell3.height + 3 + 65;
}
else if ([_isExpandList[indexPath.row] isEqual: @0])
{
return cell3.height +5;
}
else return cell3.height +3;
}
【问题讨论】:
标签: ios objective-c tableview tablecell