1
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

 if ([indexPath section] == 0) {
  switch ([indexPath row]) {

   case 0:
    [self renameExercise];
    [[self tableView] deselectRowAtIndexPath:indexPath 
            animated:YES];
    break;

   case 1:
    EditRootNoteViewController *newController = [[EditRootNoteViewController alloc] initWithNibName:@"EditNoteView"
                           bundle:nil];
    [newController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [newController setDelegate:self];
    [self presentModalViewController:newController
          animated:YES];
    [newController release];
    break;

xCode 'expects expression before EditRootNoteViewController...but why come? this same bit of code works outside this switch...which is probably some sort of clue, but i haven't the slightest of what.

griotspeak
  • 13,022
  • 13
  • 43
  • 54

3 Answers3

2

Try putting the code in a block:

...
  switch ([indexPath row]) {

   case 0:
    [self renameExercise];
    [[self tableView] deselectRowAtIndexPath:indexPath 
            animated:YES];
    break;

   case 1: {
    EditRootNoteViewController *newController = [[EditRootNoteViewController alloc] initWithNibName:@"EditNoteView" bundle:nil];
    [newController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [newController setDelegate:self];
    [self presentModalViewController:newController animated:YES];
    [newController release];
    } break;
  }

Or better yet, extract that code into a separate method.

Alejandro
  • 3,726
  • 1
  • 23
  • 29
  • dag. only one answer can be correct? well...i voted this up...but the other answer was pretty thorough on why...but this is a good answer too. (i know it isn't THAT serious, but it's all i can do to thank you) – griotspeak Oct 04 '10 at 01:04
2

It's because you can't declare a variable as the first statement of a case in a switch statement.

See this question or this question for more information.

Community
  • 1
  • 1
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
1

Is this your entire switch statement? If so, you're forgetting the

default:
break;

section.

Make sure your question includes the full method, or at least a complete one, to make it easier for us to help.

EDIT: Oh! After looking at this for a second time, if you declare new variables in a switch statement, you have to do so within curly brackets. Not sure why exactly, I ran into this problem a few weeks ago. Maybe someone can elaborate as to why this is needed?

W Dyson
  • 4,604
  • 4
  • 40
  • 68
  • It isn't the full method, i thought i was being helpful by not including the stuff after, but i can see how that might be a first thought. thanks. – griotspeak Oct 04 '10 at 00:59
  • switch statements are not required to have a default case. – JeremyP Oct 04 '10 at 09:23