特定の行の展開可能なセルを表示するテーブルビューを実装したいので、次のように 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:cellForRowAtIndexPath: を 1000 回呼び出すことです。データソースに 1000 個のデータが含まれていると、時間がかかりすぎます。
問題を解決するには?