【问题标题】:iOS Xcode: throwing erroriOS Xcode:抛出错误
【发布时间】:2011-08-03 04:40:41
【问题描述】:

我遇到了奇怪的问题

case 5:
        if(1==2) {NSLog(@"Here is a tmp stuff");}
        AuthenticationViewController *authVC = [[AuthenticationViewController alloc] initWithNibName:@"AuthenticationViewController" bundle:[NSBundle mainBundle]];
        [authVC setTitle:@"Authentication"];
            //self.authViewController = authVC;
            //[authVC release];

        [self.navigationController pushViewController:authVC animated:YES];

        break;

如果我删除了无用的 if 语句,它将无法编译。我无法理解为什么?

【问题讨论】:

  • AuthenticationViewController 已经创建并推送了,对吧?
  • 是的,afarnham 回答正确。 case 语句是一堆标签,编译器不知道范围。将所有东西都包装在 { } 中定义范围并且它可以工作

标签: ios xcode compilation


【解决方案1】:

您在 case 语句中声明了一个变量,这在 C 语言中是非法的。

有关详细信息以及如何解决此问题,请参阅以下内容:Why can't variables be declared in a switch statement?

【讨论】:

    猜你喜欢
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多