0

Hi I have here a code from didSelectRowAtIndexPath, and my problem is i cannot use switch case by calling a UIViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

TaskList *account = nil;
if (indexPath.section == 0) {
    account = [_forCheckerList objectAtIndex:indexPath.row];
}else if (indexPath.section == 1) {
    account = [_forApprovalList objectAtIndex:indexPath.row];
}else{
    account = [_forVerificationList objectAtIndex:indexPath.row];
}

NSDictionary *funcColors = (NSDictionary*)[dict objectForKey:@"funcTags"];
int tag = [[funcColors objectForKey:[account funcCd]] intValue];
FundTransferOwnViewController *sc = [[FundTransferOwnViewController alloc]init];
[self.navigationController pushViewController:sc animated:YES];
switch (tag) {
    case 10: //aca
        AutoCreditViewController *sc = [[AutoCreditViewController alloc]init];
        [self.navigationController pushViewController:sc animated:YES];
        break;
    default:
        break;
}}

On case 10, i am calling AutoCreditViewController, it always prompts with a red exclamation point saying "Expected Expression".

GenieWanted
  • 4,473
  • 4
  • 24
  • 35
lhencq
  • 505
  • 2
  • 6
  • 16

3 Answers3

1

Embed the switch case within braces { } like

switch (tag) 
{
   case 10: 
   {
      AutoCreditViewController *sc = [[AutoCreditViewController alloc]init];
      [self.navigationController pushViewController:sc animated:YES];
      break;
    }
   default:
      break;
 }
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
  • what is the reason for this why curly braces in objective c. – Aniket Kote Feb 19 '14 at 10:06
  • @AniketKote Check this links http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement http://stackoverflow.com/questions/1231198/declaring-variables-inside-a-switch-statement – Anil Varghese Feb 19 '14 at 10:18
0

When initialising a new object within a switch you need to add curly braces {. So your switch should look like this:

switch (tag) {
    case 10:
        {
            AutoCreditViewController *sc = [[AutoCreditViewController alloc]init];
            [self.navigationController pushViewController:sc animated:YES];
            break;
        }
    default:
        break;
}}
Gad
  • 2,867
  • 25
  • 35
0

Your both "sc" Objects are same name but diff Class , keep both different then see what will happn.

Kiran Gaware
  • 122
  • 6