Cómo crear NSIndexPath para TableView
-
23-09-2019 - |
Pregunta
necesito fila de borrado 1 de una mesa en una función que he definido. Para utilizar deleteRowAtIndexPath
debe utilizar un IndexPath
con una sección y fila definido. ¿Cómo puedo crear una indexpath así?
una matriz con el int {1} como único miembro se colgará; El mensaje indica que la sección NSLog debe definirse también.
* Editar -> Código relativas a la celda de eliminación:
NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil];
// [self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
// [self.tableView endUpdates];
Solución
Uso [NSIndexPath indexPathForRow:inSection:]
para crear rápidamente una ruta del índice.
Editar: En Swift 3:
let indexPath = IndexPath(row: rowIndex, section: sectionIndex)
Otros consejos
indexPathForRow
es un método de clase!
El código debe decir:
NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0] ;
Respuesta obligatorio en Swift: NSIndexPath(forRow:row, inSection: section)
Usted notará que NSIndexPath.indexPathForRow(row, inSection: section)
no está disponible en rápida y debe utilizar el primer método para construir el indexPath.
Para Swift 3 es ahora: IndexPath(row: rowIndex, section: sectionIndex)