1

テーブルビューを使用してリストを表示しています。を持つセルは 1 つだけUITableViewCellStyleValue1です。問題は、上下にスクロールすると、詳細なテキストがうまく表示されないことです。これがコードです。

    // テーブル ビュー セルの外観をカスタマイズします。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"セル";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (セル == nil) {
  if (indexPath.row == 0)
  {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
   cell.textLabel.textColor = [UIColor whiteColor];
   cell.accessoryType = UITableViewCellAccessoryDe​​tailDisclosureButton;
   cell.detailTextLabel.textColor = [UIColor yellowColor];
   cell.detailTextLabel.text = @"説明";
  }
  そうしないと
  {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   cell.textLabel.textColor = [UIColor whiteColor];
   cell.accessoryType = UITableViewCellAccessoryNone;
  }
    }

 // セルを構成します。
 cell.textLabel.text = [radioList objectAtIndex:indexPath.row];
    セルを返します。
}

誰かが私を助けることができますか?

4

1 に答える 1

3

セルの再利用を正しく処理していません。代わりにこのようにしてみてください。そうすれば、私が違うことをしていることがわかるはずです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
  UITableViewCell *cell = nil;
  if(indexPath.row == 0)
  {
   cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
   if (cell == nil)
   {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier2] autorelease];
   }
   cell.textLabel.textColor = [UIColor whiteColor];
   cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
   cell.detailTextLabel.textColor = [UIColor yellowColor];
   cell.detailTextLabel.text = @"Description";
  }
  else
  {
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.accessoryType = UITableViewCellAccessoryNone;
  }
 }

 // Configure the cell.
 cell.textLabel.text = [radioList objectAtIndex:indexPath.row];
 return cell;
}
于 2009-12-06T15:20:20.020 に答える