Disculpe la pregunta básica, pero esto me molesta desde hace un tiempo.UILabel no está actualizando
creo una vista de detalles de un uitable y tratan de establecer dinámicamente sus etiquetas, pero no están actualizando: se establecen
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
myObject *tmpObj = [[myObject objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
myViewController *tmpVC = [[myViewController alloc] initWithNibName:@"NIBfile" bundle:nil];
[tmpVC.myLabel setText:tmpObj.myTitle]; // The debugger shows the text: myTitle = "myText"
NSLog(@"%@", tmpVC.myLabel); // NSLog SHOWS NULL
[self.navigationController pushViewController:tmpVC animated:YES];
[tmpObj release];
}
las conexiones en el Interface Builder. La pestaña de Conexiones para el propietario del archivo muestra
'myLabel' - 'Label (myLabel)'
¿Alguna idea de por qué no se obtiene el valor?
Unos cuantos Observaciones:
- También he conectado un IBAction. Este método se llama correctamente cuando I haga clic en el botón conectado.
- Obtuve algunos consejos para mi declaración NSLog , si eso debería no mejor uso tmpVC.myLabel.text, pero al intentar también devuelve NULL.
- myLabel se declara como IBOutlet UILabel * myLabel en la interfaz. La propiedad se define como no atómica, retener.
He aquí la Luz:
Después de jugar un rato con él un poco más de lo trasladó la declaración pushViewController por encima de las actualizaciones de la etiqueta. Eso resolvió las actualizaciones de la etiqueta.
código de trabajo es el siguiente:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
myObject *tmpObj = [[myObject objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
myViewController *tmpVC = [[myViewController alloc] initWithNibName:@"NIBfile" bundle:nil];
[self.navigationController pushViewController:tmpVC animated:YES];
[tmpVC.myLabel setText:tmpObj.myTitle]; // The debugger shows the text: myTitle = "myText"
NSLog(@"%@", tmpVC.myLabel); // NSLog SHOWS NULL
[tmpObj release];
}
Pero no entiendo por qué tengo que empujar mi primera viewController ???
qué lo suelte cualquier parte del código que no sea el dealloc? – Codezy