Conecta
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
Pasar datos de tableView a ViewController información desincronizada
- preguntó
- Desarrolladores Apple
- 391 Vistas
- 4 Respuestas
- abierta
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
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!!
Por favor, accede o regístrate para añadir un comentario.
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...
Por favor, accede o regístrate para añadir un comentario.
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]
Por favor, accede o regístrate para añadir un comentario.
Por favor, accede o regístrate para añadir un comentario.
Por favor, accede o regístrate para responder a esta pregunta.
En el blog
-
- 52509
- 1
- Ago 31, 2017
Otras Preguntas y Respuestas
- entre Desarrolladores (Desarrolladores)
Respuestas WordPress (Usuarios WordPress)
Sin Respuesta
-
- 57
- 0
- Feb 23
-
- 108
- 0
- Dic 7, 2023
-
- 108
- 0
- Nov 30, 2023
-
- 449
- 0
- Jul 7, 2023
-
- 624
- 0
- Ago 4, 2022
-
- 677
- 0
- Feb 25, 2022
-
- 752
- 1
- Ene 1, 2022
-
- 1124
- 0
- Nov 24, 2021
- ver todas
Actividad Reciente
mozzer respondió hace 17 horas
Organizador VisualPeter respondió hace 17 horas
Organizador Visualmozzer preguntó hace 18 horas
Organizador VisualDaleGarrote respondió Mar 30
Liada con biblioteca de MusicaDaleGarrote preguntó Mar 27
Liada con biblioteca de Musica
Ultimas Respuestas
mozzer respondió
0Peter respondió
Si es por el sistema, ya que requieres macOS Ventu
1DaleGarrote respondió
Bueno, estoy probando y no doy en la tecla. Decid�
0ppenagosr respondió
Muchas gracias por tu respuesta; cometí el error
0DaleGarrote respondió
La solución: pillé una tarjeta AirPort por eBay,
0DaleGarrote respondió
Prueba con Adobe Bridge, entre otras cosas, te per
0DaleGarrote respondió
No doy en la tecla, como os comenté la App UltDat
0Ultimos Comentarios
...