0
は最近、私は本当に迷惑なバグを発見しました:重複細胞-コンテンツが
最初の内の1つのセルに巻き込まれている2つのセル(表の最初のセルとテーブルの最後のセル)の内容(と表の最後のセル)。これは私のテーブルに10のエントリを入れて、11番目を追加した場合にのみ発生します(画像参照)。
このような現象がどのように発生する可能性がありますか?
よろしく、 サシャは
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
static NSString *kCellTextField_ID = @"CellTextField_ID";
cell = [tableView dequeueReusableCellWithIdentifier:kCellTextField_ID];
if (cell == nil)
{
// a new cell needs to be created
cell = [[[UITableViewCellGradient alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellTextField_ID] autorelease];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
// a cell is being recycled, remove the old edit field (if it contains one of our tagged edit fields)
UIView *viewToCheck = nil;
viewToCheck = [cell.contentView viewWithTag:1];
if (!viewToCheck) {
[viewToCheck removeFromSuperview];
}
}
NSUInteger row = [indexPath row];
if (indexPath.section == 0) {
id objId = [[self.data objectAtIndex:row] valueForKey:kViewKey];
if ([objId isKindOfClass:[UITextField class]]) {
UITextField *textField = [[self.data objectAtIndex:row] valueForKey:kViewKey];
[cell.contentView addSubview:textField];
} else if ([objId isKindOfClass:[UISegmentedControl class]]) {
UISegmentedControl *segmentedField = [[self.data objectAtIndex:row] valueForKey:kViewKey];
[cell.contentView addSubview:segmentedField];
}
}
if (row == 0) {
[cell setPosition:UACellBackgroundViewPositionTop];
} else if (row == ([data count] - 1)) {
[cell setPosition:UACellBackgroundViewPositionBottom];
} else {
[cell setPosition:UACellBackgroundViewPositionMiddle];
}
return cell;}
あなたの側にUITableViewSourceDelegateの間違った実装に起因する未定義の動作のように見えます。 (セルのキャッシングはかなり複雑になる可能性があります) いくつかのコードを表示できますか? –
コードを投稿できる場合は、一度似たようなことをすると、cellForRowAtIndexPathメソッドで間違っていました。 – hol
質問を「回答」のコードで更新し、「回答」を削除する必要があります。 textFieldとsegmentedFieldにはどのようなタグ値がありますか?セルがリサイクルされたときにそれらが除去されていると確信していますか? – Anna