【发布时间】:2016-02-24 23:56:10
【问题描述】:
我正在尝试设置一个开关,因此如果开关打开,它会使处于完全不同视图的按钮转到与关闭开关时不同的视图。我已经完成了我的研究并找到了NSUserDefaults,但我在尝试启用它时遇到了 3 个解析错误。我的代码是:
Settings View.m(开关在哪里)
- (IBAction)mathTaskSwitched:(id)sender {
[[NSUserDefaults standardUserDefaults] setBool:switch.on forKey:@"switchState"]; //error 1
试图访问开关布尔的代码
BOOL on = [[NSUserDefaults standardUserDefaults] boolForKey:@"switchState"];
if (on) {
double delayInSeconds = seconds;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIViewController *viewController4 =
[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController4"];
[self presentViewController:viewController4 animated:YES completion:nil];
} else { //errors 2&3
double delayInSeconds = seconds;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIViewController *viewController3 =
[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController3"];
[self presentViewController:viewController3 animated:YES completion:nil];
}
1:预期表达式
2:预期的')'
3:预期的“}”
这是所有与此相关的代码,我没有编辑任何内容。
谢谢
【问题讨论】:
-
switch是关键字....不要将该名称用作变量名
标签: ios objective-c nsuserdefaults parse-error