Dans la méthode cellForRowAtIndexPath:
d'une classe UITableViewController
j'utilise le code suivant pour afficher une cellule qui contient un UITextView
.Texte de cellule réimprimé dans un UITableViewCell
Parfois, lorsque je fais défiler la table contenant la cellule et que je fais défiler la cellule UITextView
, il affiche le texte de la cellule réimprimé (comme s'il y avait deux objets UITextView
dans la cellule).
Que puis-je faire pour résoudre ce problème?
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.contentView.bounds = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITextView *textView = [[UITextView alloc] initWithFrame:cell.contentView.bounds];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textView.editable = NO;
textView.scrollEnabled = YES;
textView.backgroundColor = [UIColor clearColor];
textView.font = [UIFont fontWithName:@"Helvetica" size:14.0];
textView.text = self.description;
[cell.contentView addSubview:textView];
[textView release];
Merci Ole. Cela fonctionne très bien. –