私は[table reloaddata]を呼び出します。セルを再利用すると、セルを完全にクリアするにはどうすればよいですか?
セルは新しいデータで再描画されますが、私のUILabelsは古いUILabels上に描画されているので混乱してしまいます。
static NSString* PlaceholderCellIdentifier = @"PlaceholderCell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier] autorelease];
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.contentView.backgroundColor = [UIColor clearColor];
}
私のセルの初期化はですか?
私はそう
UILabel *theDateLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 35,140, 20)];
[theDateLabel setBackgroundColor:[UIColor clearColor]];
[theDateLabel setTextColor:[UIColor lightGrayColor]];
[theDateLabel setText:[dateFormatter stringFromDate:theDate]];
[theDateLabel setFont:[UIFont fontWithName:@"TrebuchetMS-Bold" size:15]];
[cell addSubview:theDateLabel];
[theDateLabel release];
細胞内のいくつかのより多くのラベル、同じことがありますようにUILabelを追加します。
古いラベルはセルから消えて、もはや見えなくなります。
+1は簡単で迅速な解決方法です。また、cellView自体の代わりにcontentViewを推奨することは、しばしば間違って行われるため、非常に貴重です(tableView編集モードなどを使用すると醜い結果につながります)。 – Till