i need to get a value from a stepper into a global variable. i first tried to do this,
我需要从步进器获取一个值到全局变量。我第一次尝试这样做,
NSInteger MYGlobalVariable =0;
-(IBAction)time:(UIStepper *)sender {
int value = [sender value];
MYGlobalVariable = (int)value;}
reloadtimer=[NSTimer scheduledTimerWithTimeInterval:MYGlobalVariable target:self selector:@selector(WebViewLoad:) userInfo:nil repeats:YES];}
the last part of that code was a timer from my webview, but the gvariable wont change with the stepper, so is there a way this works or ..
该代码的最后一部分是来自我的webview的计时器,但是gvariable不会随着步进器而改变,所以有一种方法可行或者......
i could do the stepper with a label and then convert that into the global variable? but i dont know how to do that either
我可以用标签做步进器然后将其转换为全局变量?但我也不知道该怎么做
1 个解决方案
#1
1
for save a user setting, use:
要保存用户设置,请使用:
for save:
保存:
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setInteger:integerStepValue forKey:@"StepperValue"];
[pref synchronize];
for read
阅读
int myStepper = [[[NSUserDefaults standardUserDefaults] integerForKey:@"StepperValue"] intValue] ;
#1
1
for save a user setting, use:
要保存用户设置,请使用:
for save:
保存:
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setInteger:integerStepValue forKey:@"StepperValue"];
[pref synchronize];
for read
阅读
int myStepper = [[[NSUserDefaults standardUserDefaults] integerForKey:@"StepperValue"] intValue] ;