我希望實現的tableview其中顯示了特定行的可擴展電池,所以我創建這將如果設置它的expandContent如下擴大我自定義表格單元格:如何指定行的高度?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *shouldExpand = [self.datasource objectAtIndex:indexPath.row];
if([shouldExpand isEqualToString:@"expand"]){
[cell setExpandContent:@"Expand"];
}
else{
[cell setTitle:@"a line"];
}
return cell;
}
然而,爲了告訴tableview中行高度,我需要執行下面的代碼:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return [cell cellHeight];
}
的問題是heightForRowAtIndexPath方法調用的tableView的1000次:的cellForRowAtIndexPath:如果我的數據源中包含1000個數據,它花費太多的時間。
如何解決這一問題?
不要叫的cellForRowAtIndexPath那麼,它的怪異做到這一點呢。請改爲查詢您的數據源。 – borrrden
你的細胞只有兩種尺寸?所有未展開的單元格的高度是否相同,並且所有展開的行都是相同的高度? –
所有非增殖的細胞都是相同的高度,但不是所有的擴展行是@rob mayoff – NOrder