Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
As indicated in the code below, what I'm trying to do is access a table view cell from within a switch-case statement. The line where I do that is bolded below. Note that the bolded line of code works if I move it out of the switch-case statement, and no other errors are generated. I tried cleaning the project, but to no avail.
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *segueIdentifier;
    NSInteger row = [indexPath row];
    NSInteger section = [indexPath section];
    if (section < [[self elements] count] - 1)
    {
    switch (row) {
        case 0:
            [B]UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];[/B] 
            segueIdentifier = @"VCSegue1";
            break;
        case 1:
            segueIdentifier = @"VCSegue3";
            break;
        default:
            break;
    }
    }
    else
    {
        segueIdentifier = @"VCSegue4";
    }
    [self performSegueWithIdentifier:segueIdentifier sender:[NSNumber numberWithInteger:[indexPath section]]];
}
 
Last edited:

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
As indicated in the code below, what I'm trying to do is access a table view cell from within a switch-case statement. The line where I do that is bolded below. Note that the bolded line of code works if I move it out of the switch-case statement, and no other errors are generated. I tried cleaning the project, but to no avail.

You can not declare variables inside a switch statement, the scope would also make "cell" invisible outside the switch even if it was allowed.
 

mfram

Contributor
Jan 23, 2010
1,307
343
San Diego, CA USA
Or you could put everything under the case 0 statement in a block. That is, put braces around it. Then you could declare a new variable. But, again, it would only have scope within that block.
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
You can not declare variables inside a switch statement, the scope would also make "cell" invisible outside the switch even if it was allowed.
That's weird, but OK. Although, a "you can't put that there" message in Xcode would've been nice.
Or you could put everything under the case 0 statement in a block. That is, put braces around it. Then you could declare a new variable. But, again, it would only have scope within that block.
I think I'll do that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.