Проблема со стилем ячейки табличного представления - UITableViewCellStyleValue1 - PullRequest
1 голос
/ 06 декабря 2009

Я использую табличное представление для отображения списка. Только одна ячейка будет иметь UITableViewCellStyleValue1. Проблема в том, что при прокрутке вверх / вниз подробный текст отображается плохо. вот код.

    // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
  if(indexPath.row == 0)
  {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
   cell.textLabel.textColor = [UIColor whiteColor];
   cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
   cell.detailTextLabel.textColor = [UIColor yellowColor];
   cell.detailTextLabel.text = @"Description";
  }
  else
  {
   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;
}

Может кто-нибудь мне помочь?

1 Ответ

3 голосов
/ 06 декабря 2009

Вы неправильно обрабатываете повторное использование ячейки. Попробуйте вместо этого сделать это, и я думаю, вы сможете увидеть, что я делаю по-другому.

- (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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...