Tengo un UITableView
personalizado usando UITableViewCell
s.
Cada UITableViewCell
tiene 2 botones. Al hacer clic en estos botones cambiará una imagen en un UIImageView
dentro de la célula.
¿Es posible actualizar cada celda por separado para mostrar la nueva imagen? Se agradece cualquier ayuda.
Una vez que tengas el indexPath de tu celda, puedes hacer algo como:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathOfYourCell, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
En Xcode 4.6 y superiores:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
Puede establecer lo que quiera como efecto de animación, por supuesto.
Intenté simplemente llamar a -[UITableView cellForRowAtIndexPath:]
, pero no funcionó. Pero, lo siguiente funciona para mí, por ejemplo. Yo alloc
y release
el NSArray
para una gestión ajustada de la memoria.
- (void)reloadRow0Section0 {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *indexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[indexPaths release];
}
Sólo para actualizar estas respuestas ligeramente con la nueva sintaxis literal en iOS 6--puedes usar Paths = @[indexPath] para un solo objeto, o Paths = @[indexPath1, indexPath2,...] para múltiples objetos.
Personalmente, he encontrado que la sintaxis literal para arrays y diccionarios es inmensamente útil y ahorra mucho tiempo. Para empezar, es más fácil de leer. Y elimina la necesidad de un nil al final de cualquier lista multi-objeto, que siempre ha sido un bugaboo personal. Todos tenemos nuestros molinos de viento, ¿no? ;-)
Sólo pensé en añadir esto a la mezcla. Espero que sirva de ayuda.