我正在设置一个开关,所以如果开关打开,它会使一个完全不同的视图中的按钮转到与开关关闭时不同的视图。我已经完成了我的研究并找到- (IBAction)mathTaskSwitched:(id)sender {
[[NSUserDefaults standardUserDefaults] setBool:switch.on forKey:@"switchState"]; //error 1
但是我试图启用此解决方案时遇到3次解析错误。我的代码是:
设置View.m(切换位置)
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];
}
尝试访问交换机bool的代码
$allegato->delete("tutti")
1:预期表达
2:预期')'
3:预期'}'
这是与此相关的所有代码,我没有编辑过任何内容。
日Thnx
答案 0 :(得分:0)
我没有看到第一部分代码有任何明显错误,所以我无法帮助你处理预期的表达式错误,但是后两个错误是由于未能关闭块上的大括号而造成的传递给dispatch_after。
例如,第一部分应为:
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];
}); // note the brace and closing paren
}
答案 1 :(得分:-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];
});// You didn't close your block
} 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];
});// You didn't close your block
}
这就是问题所在。现在在你的代码中复制并替换它,它将起作用。