plistデータソースで満たされたUITableViewを作成し、Interface Builderでカスタムセルを作成しました(したがって、xibファイルを使用しています)
セルを作成しているコードの部分は次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
DataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"DataTableViewCell" owner:nil options:nil];
for (UIView *view in views) {
if ([view isKindOfClass:[UITableViewCell class]]) {
cell = (DataTableViewCell*)view;
}
}
}
return cell;
}
次に、次を使用する場合:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
メソッドを使用して選択したセルを取得し、このメソッドを呼び出してセルを展開します。
- (void)expandCellAtIndex:(int)index {
NSMutableArray *path = [NSMutableArray new];
NSArray *currentCells = [subCellItems objectAtIndex:index];
int insertPos = index + 1;
for (int i = 0; i < [currentCells count]; i++) {
[path addObject:[NSIndexPath indexPathForRow:insertPos++ inSection:0]];
}
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
問題は、これまでにこれを行ったことがないため、展開したときに表示するセルを変更する方法についてのロジックに固執していることです。これは、メソッドが原因です。
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
正しいパスを検索し、最初にデータをロードしたものと同じセル xib ファイルを持つセルを挿入しています
以前と同じではなく、別のセル (別の xib と別のデータ) を表示するように設定するにはどうすればよいですか?
基本的にこのテーブルは機能していますが、拡大するセルには、タッチしたセルのコピーが表示されます