objective c - Storing SegmentedControl Segment State in NSUserDefaults -
i trying store segment index of segmentedcontrol
in nsuserdefaults
.
here code loading preferences , preferences 'save' button.
- (void)viewdidload { [super viewdidload]; // stored info before view loads nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; int yprefsegment = [defaults integerforkey:@"ypref"]; prefysegmentedcontrol.selectedsegmentindex = yprefsegment; } - (ibaction)saveprefbutton:(id)sender { int ypref = [[prefysegmentedcontrol.selectedsegmentindex] integervalue]; nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults synchronize]; nslog(@"data saved"); }
i getting error on line (in saveprefbutton
) :
int ypref = [[prefysegmentedcontrol.selectedsegmentindex] integervalue];
error is: expected identifier
i lost here. don't know talking about.
thank you.
you have 1 syntax error , 2 semantical errors.
the syntax error:
[prefysegmentedcontrol.selectedsegmentindex]
choose 1 of method phone call or dot notation accessing properties. utilize either
[prefysegmentedcontrol selectedsegmentindex]
or
prefysegmentedcontrol.selectedsegmentindex
the first semantical error:
prefysegmentedcontrol.selectedsegmentindex
is integer. no need phone call integervalue
on it. (you can't send messages primitive types anyway. not smalltalk.)
the sec semantical error: don't store index in nsuserdefaults
. insert
[defaults setinteger:ypref forkey:@"ypref"];
before synchronize user defaults.
objective-c nsuserdefaults
No comments:
Post a Comment