tags:

views:

88

answers:

3
- (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.

+1  A: 

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?

DysonApps
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
switch statements are not required to have a default case.
JeremyP
+1  A: 

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.

Aleph
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
+3  A: 

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.

Dave DeLong