2009-12-06 7 views
1

J'utilise une vue de table pour afficher une liste. Une seule cellule aura UITableViewCellStyleValue1. Le problème est que lorsque vous faites défiler vers le haut/bas, le texte détaillé ne s'affiche pas bien. voici le code.Problème avec le style de cellule tableview - 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; 
} 

Quelqu'un peut me aider?

Répondre

3

Vous ne gérez pas correctement la réutilisation de la cellule. Essayez de le faire à la place et je pense que vous devriez être capable de voir ce que je fais différemment.

- (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; 
} 
+0

Merci pour votre réponse. –

Questions connexes