francesco.venica
francesco.venica

Reputation: 1721

trouble passing variable

HI have a little problem, I want to pass a simple variable between 2 viewcontrollers, I try in this way but I get a null variable.

Controller1.m

SecondaVista *secondaVista = [[SecondaVista alloc] init] ;
[self.navigationController pushViewController:secondaVista animated:YES];
secondaVista.titolo = @"Ciao";

Controller2.h

NSString *titolo;
@property (nonatomic,retain) NSString *titolo;

Controller2.m

NSLog(@"%@",self.titolo);

where is the mistake?

Upvotes: 1

Views: 252

Answers (1)

Ahmed
Ahmed

Reputation: 782

try setting the variable before pushing the view.

SecondaVista *secondaVista = [[SecondaVista alloc] init] ;
secondaVista.titolo = @"Ciao"; 
[self.navigationController pushViewController:secondaVista animated:YES];

Where are you logging the variable? I mean in viewDidLoad or viewWillAppear where?

Upvotes: 1

Related Questions