2

さて、これは奇妙です

私はこのコードを持っています

- (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;
  }
}

これは問題なく動作します。

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;
  }
}

次のコンパイラエラーが発生します

/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'が宣言されていません(これで最初に使用)働き)

//その行をコメントアウトするために2つを編集するだけで、すべてがうまく機能します。

4

2 に答える 2

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;
    }
  }
}
于 2010-06-10T05:21:46.290 に答える
0

コメントアウトする代わりにNSLogステートメントを削除しても、同じエラーが発生しますか?たぶん、コンパイラは、コメントでケースブロックを開始していることを気に入らないでしょう。(ばかげている、私は知っているが、一撃の価値がありますか?)

于 2010-06-10T05:18:49.243 に答える