Pour chaque entrée de la cellule de vue de la table, j'ai besoin d'un bouton à droite, puis du texte et encore un bouton sur la gauche. À l'événement de clic sur un bouton, je dois changer le texte (bouton gauche/droit cliqué.) Et supprimer l'un des boutons en fonction des conditions de texte. Je ne suis pas en mesure de supprimer les boutons en utilisant la méthode cellForRowAtIndexPath. J'ai essayé de sous-classer UITableViewCell et d'utiliser la méthode -prepareForReuse mais je ne peux pas réinitialiser la cellule. Des idées comment puis-je y parvenir? Ou y at-il un moyen de rendre ce bouton invisible ou peut-être cacher?UITableViewCell n'est pas mis à jour
NSString *CellIdentifier = [[NSString alloc] initWithFormat:@"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[self.tableView clearsContextBeforeDrawing];
NSString *str = [listOfItems objectAtIndex:indexPath.row];
cell.text = [listOfItems objectAtIndex:indexPath.row];
cell.textColor = [UIColor blueColor];
cell.font = [UIFont systemFontOfSize:14];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *image = [UIImage imageNamed:@"Arrow_Right.png"];
CGRect frame = CGRectMake(290, 5, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
[button addTarget:self action:@selector(rightArrow_clicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *img = [UIImage imageNamed:@"Arrow_Left.png"];
CGRect frame1 = CGRectMake(5, 5, img.size.width, img.size.height);
button1.frame = frame1;
[button1 setBackgroundImage:img forState:UIControlStateNormal];
button1.backgroundColor = [UIColor clearColor];
[button1 addTarget:self action:@selector(leftArrow_clicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button1];
if([str isEqual:@" abc "])
[button setEnabled:NO];
if([str isEqual:@" pqr "])
[button1 setEnabled:NO];
Oui c'est une cellule réutilisable. Comment le réinitialiser dans la méthode -prepareForReuse? – Neo