J'ai un tableau initialisé dans mon RootViewController et une méthode qui ajouteObjects à un tableau. J'ai créé un objet RootViewController dans mon SecondViewController. La méthode s'exécute (génère un message) mais n'ajoute rien au tableau, et le tableau semble vide. Le code est ci-dessous, des suggestions?Méthode dans RootViewController ne pas stocker de tableau
RootViewController.h
#import "RootViewController.h"
#import "SecondViewController.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
myArray2 = [[NSMutableArray alloc] init];
NSLog(@"View was loaded");
}
-(void)addToArray2{
NSLog(@"Array triggered from SecondViewController");
[myArray2 addObject:@"Test"];
[self showArray2];
}
-(void)showArray2{
NSLog(@"Array Count: %d", [myArray2 count]);
}
-(IBAction)switchViews{
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
[screen release];
}
SecondViewController.m
#import "SecondViewController.h"
#import "RootViewController.h"
@implementation SecondViewController
-(IBAction)addToArray{
RootViewController *object = [[RootViewController alloc] init];
[object addToArray2];
}
-(IBAction)switchBack{
[self dismissModalViewControllerAnimated:YES];
}
EDIT *************
Avec le code de Matt Je suis l'erreur suivante :
"spécificateur-qualifier-liste attendu avant 'RootViewController'"
Laissez-moi vous demander. Le [screen setRootViewController: self] fait quoi? D'après ce que je pense, cette ligne de code fait presque le RootViewController le contrôleur natif lorsque la plume de SecondViewController est chargée? – Tony
Il donne simplement à votre SecondViewController une référence au RootViewController afin qu'il puisse y accéder et appeler sa méthode -addToArray2 que vous avez créée. Je ne suis pas sûr de ce que vous entendez par contrôleur * natif *. –
Peu importe que vous avez effacé ma confusion :) Je vais essayer cela. Merci pour l'explication. – Tony