1

I'm new to iOS, my question is: What is the best way to pass data from one UIViewController to another, through singleton class or *.h file?

Camsoft
  • 11,718
  • 19
  • 83
  • 120
  • 2
    Refer this :- http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers/22934200#22934200 – borncrazy Apr 09 '14 at 11:51

1 Answers1

1

1) use properties to pass data.

- (void)someMethod {
  MyViewController * vc = [[MyViewController alloc] initWithNibName:"MyViewController" bundle:nil];
  vc.someData = data;
} 

Also if you use Segues you should do it prepareForSegue method

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    MyViewController *vc = segue.destinationViewController;
    vc.someData = data;
}
Leandros
  • 16,805
  • 9
  • 69
  • 108
Kostiantyn Koval
  • 8,407
  • 1
  • 45
  • 58