pasar datos entre vistas
Así que estoy tratando de pasar datos entre dos vistas (la primera vista es tableViewController, cuando se presiona la celda, los datos se envían a la segunda vista, la segunda vista tiene imageView, cuando se muestran los datos se muestra la imagen) usando este tutorialiphonedevsdk.
Estoy usando lo mismotheAppDataObject método en mis opiniones:
- (AppDataObject*) theAppDataObject
{
id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
AppDataObject* theDataObject;
theDataObject = (AppDataObject*) theDelegate.theAppDataObject;
return theDataObject;
}
Cuando se presiona la celda estoy tratando de enviar datostheAppDataObject.imageString = tempImageString;
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
tempImageString = (((championList *) [self.champions objectAtIndex:indexPath.row]).championImage);
AppDataObject *theDataObject = [self theAppDataObject];
NSLog(@"tempIm-g = %@",tempImageString);
theDataObject.imageString = tempImageString;
NSLog(@"theAppDataObject.imageString = %@",theDataObject.imageString);
[self.navigationController popToRootViewControllerAnimated:YES];
}
Salida NSLog:
tempIm-g = Champ_0.jpg
theAppDataObject.imageString = (null)
SecondViewController (mostrar imagen):
-(void)viewWillAppear:(BOOL)animated
{
AppDataObject* theDataObject = [self theAppDataObject];
UIImage *tempImage = [UIImage imageNamed:theDataObject.imageString];
NSLog(@"temp image = %@",tempImage);
[choosenChampionImageView setImage:tempImage];
}
Salida NSLog:
imagen temporal = (nula)
Mi problema es que theAppDataObject.imageString siempre es nulo
Posibles soluciones que conozco:
No use AppDataObject como contenedor de datos genéricos y solo guarde los datos en appDelegate.
Ex.:
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
appdelegate.imageString = tempImageString;
Pero quiero averiguar cómo usar los protocolos.
Lo que intenté: Hacer elDataObject global:
vista1.h
@interface championsListTableViewController : UITableViewController
{
NSString *tempImageString;
AppDataObject* theDataObject;
}
@property(strong,nonatomic) NSString *tempImageString;
@property(strong,nonatomic) AppDataObject* theDataObject;
salida de NSLog (@ "theDataObject is% @", theDataObject); :
theDataObject es (nulo), ¿cómo es esto posible?