2

我想确保没有任何变量(name, adres,code等)是nil. 这是我尝试过的:

if (name == nil && adres == nil && code == nil && place == nil && telNr == nil && mail == nil) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"EXAMPLE"
                                                    message:@"EXAMPLE "
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];

} else { //do the rest }

问题是,当其中一个变量不是 nil 时,它会运行 else 语句,但是我想确保没有一个变量是 nil。

我试过|而不是,&&但它当然更糟。

4

1 回答 1

3

逻辑OR( ||) 应该有效。这就像说,如果其中任何一个是nil显示弹出窗口,如果没有,则转到 else 分支。

如果您实际使用|and not ||,请注意这|是按位包含运算符,而不是逻辑运算符。

于 2013-01-08T19:39:20.590 回答