ios - Convertir NSInteger a NSIndexpath
objective-c (4)
Básicamente, estoy almacenando un índice de una matriz en un NSInteger. Ahora lo necesito como un NSIndexpath, estoy luchando para ver y encontrar una forma de convertir mi NSInteger a NSIndexpath para poder reutilizarlo.
Para un index int:
NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
Crea el índice del elemento en el nodo 0 para señalar según la referencia .
Para usar indexPath en una UITableView , el método más apropiado es
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
Use los métodos a continuación de la clase NSIndexPath .
+ (id)indexPathWithIndex:(NSUInteger)index;
+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length;
- (id)initWithIndex:(NSUInteger)index
Use como se myIndexPath continuación y también No olvide release objeto myIndexPath después de usar.
NSIndexPath *myIndexPath = [[NSIndexPath alloc] initWithIndex:[myIntObj intValue]];
Si necesita un NSIndexPath para una UITableView , puede usar indexPathForRow:inSection: ( reference ). Las rutas de índice pasadas a la vista de tabla deben contener exactamente dos índices que especifiquen la sección y la fila. Una ruta de índice creada con indexPathWithIndex: solo contiene un índice y no funcionará con una vista de tabla.
Swift 3:
let indexPath = IndexPath(row: 0, section: 0)