passando dados entre vistas
Então, eu estou tentando passar dados entre duas visões (a primeira vista é tableViewController, quando a célula é pressionada, os dados são enviados para a segunda visualização, a segunda visualização tem a imageView, quando os dados são enviados, a imagem é mostrada) usando este tutorialiphonedevsdk.
Estou usando o mesmotheAppDataObject método em minhas visualizações:
- (AppDataObject*) theAppDataObject
{
id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
AppDataObject* theDataObject;
theDataObject = (AppDataObject*) theDelegate.theAppDataObject;
return theDataObject;
}
Quando a célula é pressionada, estou tentando enviar dadostheAppDataObject.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];
}
Saída NSLog:
tempIm-g = Champ_0.jpg
theAppDataObject.imageString = (nulo)
SecondViewController (mostre a imagem):
-(void)viewWillAppear:(BOOL)animated
{
AppDataObject* theDataObject = [self theAppDataObject];
UIImage *tempImage = [UIImage imageNamed:theDataObject.imageString];
NSLog(@"temp image = %@",tempImage);
[choosenChampionImageView setImage:tempImage];
}
Saída NSLog:
temp image = (null)
Meu problema é que o AppDataObject.imageString é sempre nulo
Possíveis soluções que eu conheço:
Não use o AppDataObject como recipiente de dados genérico e apenas salve os dados no appDelegate.
Ex.:
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
appdelegate.imageString = tempImageString;
Mas eu quero descobrir como usar protocolos.
O que eu tentei: Make theDataObject global:
view1.h
@interface championsListTableViewController : UITableViewController
{
NSString *tempImageString;
AppDataObject* theDataObject;
}
@property(strong,nonatomic) NSString *tempImageString;
@property(strong,nonatomic) AppDataObject* theDataObject;
saída de NSLog (@ "theDataObject is% @", theDataObject); :
theDataObject é (null), como isso é possível?