Reputation: 360
For some reason this switch statement don't want to recognise my view controller classes names nor the adhering variables (IndexViewController adhere indexVC). If I were to do it in a regular if or without dependency statements, it does recognise the same piece of code. I actually looked up the syntax of switch, because I thought my mind had leaked some memory. But syntax seems alright. Can anybody point out my error? Thanks
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
IndexViewController *indexVC = [self.storyboard instantiateViewControllerWithIdentifier:@"IndexViewController"];
[self.currentVC presentViewController:indexVC animated:YES completion:nil];
break;
case 1:
ProtectionViewController *proVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ProViewController"];
[self.currentVC presentViewController:proVC animated:YES completion:nil];
break;
case 2:
UsersViewController *usersVC = [self.storyboard instantiateViewControllerWithIdentifier:@"UsersViewController"];
[self.currentVC presentViewController:usersVC animated:YES completion:nil];
break;
case 3:
StatisticsViewController *statisticsVC = [self.storyboard instantiateViewControllerWithIdentifier:@"StatisticsViewController"];
[self.currentVC presentViewController:statisticsVC animated:YES completion:nil];
break;
default:
NSLog(@"We dont beleive in defaults");
break;
}
}
Upvotes: 1
Views: 37
Reputation: 54630
You need to give the case-local variables scope:
switch (indexPath.row) {
case 0: {
IndexViewController *indexVC = [self.storyboard instantiateViewControllerWithIdentifier:@"IndexViewController"];
[self.currentVC presentViewController:indexVC animated:YES completion:nil];
break;
}
case 1: {
...
}
...
Add the braces.
Upvotes: 2