-1

I know how to pass a variable from the first view to the second view by using the"PrepareForSeque" . But I would like to pass the variable to the fifth view and there is not any transition between the first and fifth view. Can you help me please?

Mina Best

MKH
  • 153
  • 1
  • 3
  • 15
  • 1
    http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Anna Dickinson Nov 01 '14 at 18:26
  • Personally, I would use a Singleton. Here is a tutorial about Singletons and other common design patterns in ios: http://www.raywenderlich.com/46988/ios-design-patterns – Anna Dickinson Nov 01 '14 at 18:30

2 Answers2

1

you can go with NSUserDefaults by saving and retrieving data

NSString *valueToSave = @"someValue";
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"preferenceName"];
[[NSUserDefaults standardUserDefaults] synchronize];

NSString *savedValue = [[NSUserDefaults standardUserDefaults]
    stringForKey:@"preferenceName"];

or

create on variable in AppDelegate and Access that value by sung AppDelegate Object.

Balu
  • 8,470
  • 2
  • 24
  • 41
  • 1
    NSUserDefaults are for storing state over multiple executions of the app -- it's inefficient to use them in this context. – Anna Dickinson Nov 01 '14 at 18:23
0

You can just pass the data through scenes using class methods.

FirstViewController:

In your .m file declare:

static NSInteger* staticScore;

Create class method and return this value:

+ (NSInteger*) passScore {
   return staticScore;
}

In FifthViewController #import this class and get value like this:

[FirstViewController passScore];
Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84