我想确保没有任何变量(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。
我尝试了 |
而不是 &&
但当然更糟糕。
最佳答案
逻辑OR
(||
) 应该有效。这就像说,如果其中任何一个 nil
显示弹出窗口,如果没有,则转到 else 分支。
如果您实际上使用了 |
而不是 ||
,请注意 |
是按位包含运算符,而不是逻辑运算符。
关于ios - 如果语句没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14222667/