2011-11-08 3 views
0

J'utilise un UITableView dans mon application et l'exigence est quand j'appuie sur une cellule de mon UITableView pour passer à la vue suivante la couleur de cette cellule particulière devrait être changée au bleu.Comment changer la couleur d'un UITableViewCell en bleu quand est sélectionné

Comment puis-je faire ceci est mon code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *MyIdentifier = @"dealsCC"; 
    dealsCC *cell = (dealsCC *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    [cell selectionStyle:UITableViewCellSelectionStyleBlue]; 
} 

S'il vous plaît me dire,

Thanx à l'avance.

Répondre

0

Définissez le style de sélection.

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 
+1

Je l'ai essayé, mais il ne fonctionne pas. – iPhone

0

dans le didSelectRowAtIndexPath vous devez écrire ce code

UITableViewCell *cell = [table cellforRowAtIndexPath:indexPath.row]; 
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 
+0

Je l'ai essayé mais ça ne marche pas, y a-t-il une autre méthode? – iPhone

+0

écrivez le code ci-dessous dans cellforRowAtIndexPath [cell setSelectionStyle: UITableViewCellSelectionStyleBlue]; – Tendulkar

+0

effectivement j'ai écrit le code suivant: – iPhone

0
// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"myCellId"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     UIView *v = [[[UIView alloc] init] autorelease]; 
     v.backgroundColor = [UIColor redColor]; 
     **cell.selectedBackgroundView = v;** 
    } 
    // Set up the cell... 
    cell.textLabel.text = @"foo"; 
    return cell; 
} 
0

Yeap. je le fais comme ça

UIView *bgColorSelected = [[UIView alloc] init]; 
    [bgColorSelected setBackgroundColor:[UIColor colorWithRed:180.0f/255.0f green:36.0f/255.0f blue:21.0f/255.0f alpha:1.0f]]; 
    cell.selectedBackgroundView = bgColorSelected; 
    [bgColorSelected release]; 
    cell.backgroundColor = [ UIColor clearColor]; 
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = 
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:CellIdentifier]; 
    } 

    cell.selectionStyle = UITableViewCellSelectionStyleBlue; 

    return cell; 
} 
0
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
} 
Questions connexes