Do you want to pass the integer value to the other view

advertisements

I am creating an iphone app in which i have some vale in integer in my oneviewcontroller and i want that integer value in my secondviewcontroller controller.

value will be random. I stored this integer value in id score

Nw I am using this code but,i cant get integer value.

CODE : passing integer value from one UIView to another UIview

Integer Value always becomes zero at the secondviewcontroller.
Any Help will be appreciated.
Thanks.

MY CODE:

FirstView.h file

NSInteger myScore;
id score;
NSInteger totalscore;

.m file

NSInteger *cal = (myScore * 100)/400  ;

        totalscore = cal;
        score = totalscore;

SecondView.h file

 int scorevalue ;

SecondView.m file

FirstViewController *firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
value = firstVC.Score;
NSLog(@"SCORE : %d" ,value );


Example:

If I need to store the int value 4 in FirstViewController,

[[NSUserDefaults standardUserDefaults] setObject:4 forKey:@"integer"];
[[NSUserDefaults standardUserDefaults] synchronize];

I can get the get in the SecondViewController as,

int value = [[NSUserDefaults standardUserDefaults] objectForKey:@"integer"]
NSLog(@"integer = %d", [[NSUserDefaults standardUserDefaults] objectForKey:@"integer"]);

Hope it will work perfectly.