// wrote function in separate class file:
-(void)display { nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; nsinteger *position = [prefs integerforkey:@"currentlevel"]; nslog(@"------->%i",position); //this nslog returning value 6 [prefs synchronize]; } //in viewcontroller calling function using object have created class
@interface viewcontroller () { //display class name //disp object fro class display *disp; } @implementation viewcontroller - (void)viewdidload { disp = [[display alloc]init]; [disp display]; nslog(@"%i",[disp position]); //this nslog statement returning value 0 [super viewdidload]; } if has solution please me.
try implement this..
@implementation classa - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. [[nsuserdefaults standarduserdefaults]setinteger:100 forkey:@"currentlevel"]; [[nsuserdefaults standarduserdefaults] synchronize]; } @end @implementation classb - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. int b = [[[nsuserdefaults standarduserdefaults] integerforkey:@"currentlevel"] integervalue]; nslog(@"interger value %d",b); }
Comments
Post a Comment