在iOS中切换错误

时间:2014-06-20 08:51:03

标签: ios switch-statement uialertview

我尝试使用开关

执行不同的功能
   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;
        }

case 10:下的行会报告错误expected expression,我不明白,你能帮助我吗?

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

这些代码报告错误。

1 个答案:

答案 0 :(得分:-3)

将NSLog放在UIALertview上,你会看到错误将消失......是的,我们不能在切换案例中直接初始化UIAlertview ....它应该在{}。

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

            break;


    }