我想在每個單元格內用一些長文本構建一個UITableView。單元格沒有AccessoryView,除了一個單元格(第8個單元格),這是一種打開詳細信息視圖的按鈕。單UITableViewCell與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被添加到一個隨機點(或多或少的第三個單元格,但我不知道它是否在它的內部或隨機浮動)。 是否與iOS重新使用單元有關?我怎樣才能避免它?
在此先感謝。