Nido Apple

Recibe ayuda de expertos

Registrate y pregunta

Es gratis y fácil

Recibe respuestas

Respuestas, votos y comentarios

Vota y selecciona respuestas

Recibe puntos, vota y da la solución

Pregunta

0voto

Disculparme soy principiante y no sé ni como explicar mi problema, espero que se entienda :( Tengo un tableView que recibe datos sqlite a través de un objeto y quiero pasarlos a un view controller, el problema que tengo es que al seleccionar la celda en el view controller de destino me muestra el ultimo objeto de la sqlite y al seleccionar otra me muestra la celda que había seleccionado primero y así continuamente. Te copio donde creo que esta el problema: [PHP]- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"CeldaReinado"forIndexPath:indexPath] datoPrueba = (MonedaCat *)[_arrayMonedas objectAtIndex:indexPath.row]; UILabel *etiqueta = (UILabel *) [cell viewWithTag:1]; etiqueta.text = [datoPrueba valor_moneda]; UIImageView *etiquetaImagen = (UIImageView *) [cell viewWithTag:101]; etiquetaImagen.image = [UIImage imageNamed:[datoPrueba imagen_rev]]; UIImageView *etiquetaImagenAnv = (UIImageView *) [cell viewWithTag:102]; etiquetaImagenAnv.image = [UIImage imageNamed:[datoPrueba imagen_anv]]; return cell; } //Al seleccionar una celda... - (void) tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { datoPrueba = (MonedaCat *)[_arrayMonedas objectAtIndex:indexPath.row]; } - (void)prepareForSegue: (UIStoryboardSegue *)segue sender: (id)sender { if ([segue.identifierisEqualToString: @"detalleSegue"]) { DetallesViewController *pasarDatos = [segue destinationViewController]; pasarDatos.detalleValor = datoPrueba.valor_moneda; } }[/PHP] Muchas gracias!!!

4 Respuestas

0voto

VictorGp Puntos520
Hola a todos, os escribo unos detalles para ver si alguien entiende lo que me pasa. Añadiendo un NSLog al método "didSelect" me muestra correctamente los datos seleccionados, pero en el "prepareForSegue" el NSLog la primera vez que selecciono la celda lo muestra null y al volver atrás y seleccionar otra me muestra la selección de antes. Un ejemplo: "didSelect" "prepareFor" - Selecciono celda 1 . NSLog = 1 NSLog = nill - Selecciono celda 4. NSLog = 4 NSLog = 1 - Selecciono celda 6. NSLog = 6 NSLog = 4 y así sucesivamente. Muchas Gracias y saludos!!

0voto

VictorGp Puntos520
Un ejemplo de lo que me ocurre, dos vista y paso datos al NavigationItem. [PHP]VistaUno.h #import @interface VistaUno : UITableViewController @property (strong, nonatomic) NSString *nombreRey; @property (strong, nonatomic) VistaUno *objRei; @property (strong, nonatomic) NSMutableArray *reyes; @end VistaUno.m #import "VistaUno.h" #import "VistaDos.h" @interfaceVistaUno () @end @implementation VistaUno - (id)initWithStyle: (UITableViewStyle)style { self = [superinitWithStyle:style]; if (self) { // Custom initialization } returnself; } - (void)viewDidLoad { _reyes = [[NSMutableArray alloc] init]; _objRei = [[VistaUno alloc] init]; _objRei.nombreRey = @"Isabel"; [_reyes addObject: _objRei]; _objRei = [[VistaUno alloc] init]; _objRei.nombreRey = @"Amadeo"; [_reyesaddObject:_objRei]; _objRei = [[VistaUno alloc] init]; _objRei.nombreRey = @"Alfonso"; [_reyes addObject:_objRei]; _objRei = [[VistaUno alloc] init]; _objRei.nombreRey = @"Felipe V"; [_reyes addObject:_objRei]; [superviewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView: (UITableView *)tableView { return 1; } - (NSInteger)tableView: (UITableView *)tableView numberOfRowsInSection: (NSInteger)section { return _reyes.count; } - (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"Celda"forIndexPath:indexPath]; _objRei = [_reyes objectAtIndex:indexPath.row]; UILabel *etiqueta = (UILabel *) [cell viewWithTag:1]; etiqueta.text = _objRei.nombreRey; return cell; } - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { _objRei = [_reyes objectAtIndex:indexPath.row]; NSLog(@"%@",_objRei.nombreRey); } - (void)prepareForSegue: (UIStoryboardSegue *)segue sender: (id)sender { if ([segue.identifierisEqualToString: @"segue"]) { VistaDos *pasaDato = [segue destinationViewController]; pasaDato.navigationItem.title = _objRei.nombreRey; } } @end[/PHP] El NSLog del didselect muestra bien los datos pero al pasar por el prepareforsegue va con retraso. Gracias a todos...

0voto

VictorGp Puntos520
Arreglado!! :) He acabado por eliminar el prepareForSegue :( [PHP](void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath { //hago instancia de la vista a la que quiero ir indicando el identificador de la vista DetailViewController *dVC = [self.storyboard instantiateViewControllerWithIdentifier:mad:"detailViewController"];[self.navigationController pushViewController:dVC animated:YES];[/PHP]

0voto

Peter Puntos289170
Gracias por compartir la solución! :D

Por favor, accede o regístrate para responder a esta pregunta.

Otras Preguntas y Respuestas


Actividad Reciente

...