私は問題があります。テーブルビューを実装しました。メソッドではdidSelectRowAtIndexPath
、セルの高さを増やし、そのセルにテキストビューを追加しcontentView
ます。しかし、テーブル ビューを下にスクロールすると (たとえば 10 セルの場合)、同じテキストビューが再び表示されます。手伝ってくれませんか?
問題をよりよく理解するためのコードを次に示します。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedIndex == indexPath.row)
{
return CELL_HEIGHT * 5;
}
return CELL_HEIGHT;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
if (selectedIndex == indexPath.row)
{
selectedIndex = -1;
[[cell.contentView viewWithTag:COOL_TAG] removeFromSuperview];
}
else
{
UITableViewCell *previousCell = [aTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]];
if ([previousCell.contentView viewWithTag:COOL_TAG])
{
[[previousCell.contentView viewWithTag:COOL_TAG] removeFromSuperview];
}
selectedIndex = indexPath.row;
UITextView *text = [[UITextView alloc] initWithFrame:CGRectMake(10, 45, 255, 180)];
[text.layer setBackgroundColor:[[UIColor whiteColor] CGColor]];
[text.layer setBorderColor:[[UIColor grayColor] CGColor]];
[text.layer setBorderWidth:1.0f];
[text.layer setCornerRadius: 8.0f];
[text.layer setMasksToBounds:YES];
[text setEditable:NO];
text.text = [questionArray objectAtIndex:indexPath.row];
text.tag = COOL_TAG;
[cell.contentView addSubview:text];
}
[tableView beginUpdates];
[tableView endUpdates];
}
前もって感謝します!