删除NSLog会破坏编译器

DVG*_*DVG 2 iphone nslog uitableview

好的,所以这很奇怪

我有这个代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
  case 1:
    NSLog(@"Platform Cell Selected");
    AddGamePlatformSelectionViewController *platformVC =
      [[AddGamePlatformSelectionViewController alloc]
      initWithNibName:@"AddGamePlatformSelectionViewController" bundle:nil];
    platformVC.context = context;
    platformVC.game = newGame;
    [self.navigationController pushViewController:platformVC animated:YES];
    [platformVC release];
    break;
  default:
    break;
  }
}
Run Code Online (Sandbox Code Playgroud)

哪个工作正常.

当我删除NSLog语句时,如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
  case 1:
    //NSLog(@"Platform Cell Selected");
    AddGamePlatformSelectionViewController *platformVC =
      [[AddGamePlatformSelectionViewController alloc]
      initWithNibName:@"AddGamePlatformSelectionViewController" bundle:nil];
    platformVC.context = context;
    platformVC.game = newGame;
    [self.navigationController pushViewController:platformVC animated:YES];
    [platformVC release];
    break;
  default:
    break;
  }
}
Run Code Online (Sandbox Code Playgroud)

我得到以下编译器错误

/Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:102:0 /Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:102:错误:'AddGamePlatformSelectionViewController'之前的预期表达式

/Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:103:0 /Users/DVG/Development/iPhone/Backlog/Classes/AddGameTableViewController.m:103:错误:'platformVC'undeclared(在此首次使用)功能)

如果我只是编辑出两个//来评论那条线,那么一切都可以正常运行.

Mic*_*ler 5

你不能声明一个对象(例如AddGamePlatformSelectionViewController *platformVC)在第一线case......

您可以通过在(例如NSLog)之前添加一些代码或通过将代码包含case在{...}之间来解决它,如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  switch (indexPath.row) {
    case 1:
    {
      AddGamePlatformSelectionViewController *platformVC = [[AddGamePlatformSelectionViewController alloc]
      initWithNibName:@"AddGamePlatformSelectionViewController" bundle:nil];
      // the rest of the code...
      break;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)