こんにちは、私はこの問題で 2 日連続で立ち往生しているので、手を差し伸べてくれる人がいるかどうか尋ねています。
4 つのセクションで構成されるテーブルビューがあります。
セクション 1 -> セルに uiimageview であるサブビューが含まれる 1 行だけで構成されます
セクション 2 -> 2 つの通常の行で構成されます (テキストを含む 2 つの単純な単純なセルのみ)
セクション 3 -> 通常の 1 行で構成
セクション 4 -> 1 行で構成され、そのセルには動的テキストを含むことができる uitextview であるサブビューが含まれているため、uitextview の高さ、したがってセルの高さは、uitextview 内のテキストの量によって異なります。
この構造を作成するコードは次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//create a nsstring object that we can use as the reuse identifier
static NSString *CellIdentifier = @"Cell";
//check to see if we can reuse a cell from a row that has just rolled off the screen
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//if there re no cells that can be reused, create a new cell
if(cell==nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
switch (indexPath.section) {
case 0:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView addSubview:_viewForImageHeader];
break;
case 1:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = 0;
cell.textLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:16.0];
break;
case 2:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:16.0];
break;
default:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.contentView addSubview:_textViewForArticle];
break;
}
}
else{
NSLog(@"in else");
}
//here i fill in the 2 normal cells with text
return cell;
}
uitableview が (ポートレート モードで) 読み込まれると、すべてが完璧になります (画像はセクション 1 にあり、セクション 2 と 3 には正しいテキストが含まれ、セクション 4 には動的テキストがあります)。しかし、アプリを回転させ始めると、すべてのセルが混同されます。たとえば、セクション 4 でセクション 3 の内容を見つけたり、その逆を行ったりします。
これは、セルを正しく再利用していない可能性があるという事実に関係していると思います。タグを使用する必要がありますか? その場合、特定のケースでタグの使用を実装するにはどうすればよいですか?