przekazywanie danych między widokami

Próbuję przekazać dane między dwoma widokami (pierwszy widok to tableViewController, gdy komórka jest wciśnięta dane są wysyłane do drugiego widoku, drugi widok ma imageView, gdy dane są wysyłane wyświetlany jest obraz) za pomocą tego samouczkaiphonedevsdk.

Używam tego samegotheAppDataObject metoda w moich poglądach:

- (AppDataObject*) theAppDataObject
{
    id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
    AppDataObject* theDataObject;
    theDataObject = (AppDataObject*) theDelegate.theAppDataObject;
    return theDataObject;
}

Po naciśnięciu komórki próbuję wysłać danetheAppDataObject.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];
}

Wyjście NSLog:

tempIm-g = Champ_0.jpg

theAppDataObject.imageString = (null)

SecondViewController (pokaż obraz):

-(void)viewWillAppear:(BOOL)animated
{
    AppDataObject* theDataObject = [self theAppDataObject];
    UIImage *tempImage = [UIImage imageNamed:theDataObject.imageString];
    NSLog(@"temp image = %@",tempImage);
    [choosenChampionImageView setImage:tempImage];
}

Wyjście NSLog:

temp image = (null)

Moim problemem jest to, żeAppDataObject.imageString ma zawsze wartość null

Możliwe rozwiązania, które znam:

Nie używaj AppDataObject jako ogólnego kontenera danych i po prostu zapisz dane w appDelegate.

Dawny.:

AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
appdelegate.imageString = tempImageString;

Ale chcę dowiedzieć się, jak korzystać z protokołów.

Co próbowałem: Make theDataObject global:

view1.h

@interface championsListTableViewController : UITableViewController
{
    NSString *tempImageString;

    AppDataObject* theDataObject;
}

@property(strong,nonatomic) NSString *tempImageString;

@property(strong,nonatomic) AppDataObject* theDataObject;

wydajność NSLog (@ "theDataObject to% @", theDataObject); :

theDataObject jest (null), jak to możliwe?

questionAnswers(3)

yourAnswerToTheQuestion