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.Convertir NSInteger a NSIndexpath
Respuesta
Para un int index
:
NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
Crea índice del elemento en el nodo 0 a punto como por the reference.
Para utilizar el indexPath en un UITableView
, el método más apropiado es
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
Gracias. ¿Todavía puedo hacer path.row o me estoy cruzando mis eiders? – Dan
Utilice los siguientes métodos de la clase NSIndexPath.
+ (id)indexPathWithIndex:(NSUInteger)index;
+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length;
- (id)initWithIndex:(NSUInteger)index
uso que a continuación y también No se olvide de release
myIndexPath
objeto después de usar.
NSIndexPath *myIndexPath = [[NSIndexPath alloc] initWithIndex:[myIntObj intValue]];
Si necesita un NSIndexPath
para un UITableView
, puede utilizar 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)
- 1. Cómo convertir NSIndexPath a NSInteger?
- 2. Cómo convertir NSIndexpath en NSInteger o simplemente int?
- 3. ¿Convertir NSInteger a NSUInteger?
- 4. cómo convertir NSinteger a String
- 5. Cómo convertir un NSInteger a un int?
- 6. ¿Cómo puedo convertir un NSInteger a NSTimeInterval
- 7. ¿Cómo convertir un doble a NSInteger?
- 8. ¿Convierte NSString a NSInteger?
- 9. Cómo convertir NSInteger a un valor binario (cadena)
- 10. Añadir NSInteger a NSMutableData
- 11. ¿Es posible enviar un NSInteger a NSNumber?
- 12. conversión de NSNumber a NSInteger
- 13. añadiendo objeto NSInteger a NSMutableArray
- 14. Cómo incrementar un NSIndexPath
- 15. Establezca NSIndexPath programmatically
- 16. tipos NSInteger
- 17. ¿NSIndexPath es seguro para hilos?
- 18. Cómo crear NSIndexPath para TableView
- 19. Pasando variables NSInteger a NSMutableDictionary o NSMutableArray
- 20. ¿Cómo puedo obtener los valores específicos de una NSIndexPath
- 21. Comparar NSNumber con NSInteger
- 22. correctamente la conversión de NSString a CGFloat, NSInteger, etc
- 23. NSInteger cuenta por 4?
- 24. ¿Cómo comparar dos NSInteger?
- 25. ¿Devuelve NSIndexPath desde la celda personalizada? (UITableView)
- 26. ¿Por qué hay un NSInteger?
- 27. NSNotFound, NSInteger, NSUInteger y NSRange.location
- 28. int vs NSNumber vs NSInteger
- 29. Cómo convertir NSNumber a NSString
- 30. Comprobar si un objeto es NSInteger
¿Qué necesita el 'NSIndexPath' para? ¿Lo necesita para un 'UITableView'? – albertamg
Se usa cuando se llama a una declaración de actualización para sqlite. Creo que ahora me convertí a NSIndexPath pero necesito NSIndexPath.row y esto arroja un error. ¿Algunas ideas? – Dan
No puede ** llamar ** a 'row' en una ruta de índice creada con' indexPathWithIndex: '. Para crear una ruta de índice puede llamar 'row' en ella, puede usar' indexPathForRow: inSection: '. – albertamg