各セル内に長いテキストを含むUITableViewを作成しようとしています。1つのセル(8番目のセル)を除いて、セルにはAccessoryViewがありません。これは、詳細ビューを開くための一種のボタンです。
このコードを考えてみましょう:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize size = [[quotes objectAtIndex:indexPath.row] sizeWithFont:16 constrainedToSize:CGSizeMake(self.view.frame.size.width, CGFLOAT_MAX)];
return size.height+20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = [quotes objectAtIndex:indexPath.row];
if(indexPath.row==7){
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
}
return cell;
}
それは機能しますが、問題は、テーブルの一番下までスクロールして(8番目も最後の行です)、上に戻ると、別のAccessoryViewがランダムなポイント(多かれ少なかれ3番目)に追加されることです。セルですが、それがその中にあるのか、ランダムに浮かんでいるのかはわかりません)。iOSによる細胞の再利用に関係するものですか?どうすればそれを回避できますか?
前もって感謝します。