0

I try to do different function by using switch

   switch (self.requestID) {
            case 0:
                [self setTableData:[jsonDic objectForKey:@"listinofs"]];
                if ([self.tableData count] != 0) {
                    [self.dbTableView reloadData];
                }
                break;
            case 10:
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"great!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alertView show];
                break;
            default:
                break;
        }

but the line under case 10: will report error expected expression, i don't understand, can you help me?

   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"great!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alertView show];

those codes report error.

Bin
  • 484
  • 1
  • 6
  • 18
  • 1
    Place the two statements for the alert view inside {} and all should be fine. Or change it to [[[UIAlertView alloc] initWithTitle:nil message:@"great!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]; – Nick Jun 20 '14 at 08:52

1 Answers1

-3

Put NSLog over UIALertview and you will see that error will gone....Yes we can not directly initialise UIAlertview in switch case....it should be in {}.

switch (val) {
        case 10:
        {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"great!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alertView show];
        }

            break;


    }
Vibha Singh
  • 623
  • 4
  • 9