0

这可能不是 Stackoverflow 上最难解决的问题,但我似乎无法弄清楚......

我有一个 switch 语句,在这个 switch 语句中我想要一个代表文本字段的局部变量。所以我可以将其设置为安全。这是我使用的代码:

[(UITextField * )[cell.contentView viewWithTag:TABLE_TEXT_FIELD_TAG] setSecureTextEntry:YES]; // Works

现在我想设置更多的属性,因此需要(不是真的需要,而是好的编码原则)局部变量。我用这个:

case 1:   
        UITextField *textFieldPassword = (UITextField *)[cell.contentView viewWithTag:TABLE_TEXT_FIELD_TAG]; 
        // Error I get: Expected expression
        break;

为什么编译器会抱怨这个?

4

2 回答 2

1

只需这样做:

case 1:   
{
        UITextField *textFieldPassword = (UITextField *)[cell.contentView viewWithTag:TABLE_TEXT_FIELD_TAG]; 
        // Error I get: Expected expression
        break;
}
于 2013-10-03T08:03:08.030 回答
0

当在多行中使用 switch 语句时,应使用括号。

case 1:   {
    UITextField *textFieldPassword = (UITextField *)[cell.contentView viewWithTag:TABLE_TEXT_FIELD_TAG]; 
    // Error I get: Expected expression
    break;
}
于 2013-10-03T08:53:11.943 回答