ios - 如果语句没有按预期工作

标签 ios xcode if-statement

我想确保没有任何变量(nameadrescode 等)为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/

相关文章:

iOS - bodyWithPolygonFromPath : Body is the same as the path but collisions are not working properly

swift - 将 Firebase 导入 Xcode 项目时出现问题

xcode - 在 Swift 中的类之间传递变量

java - 在 Java 中是否遵循 true?

c# - VB "If(a & b)"中这个语法的含义是什么

ios - 将值设置为 nil - swift/parse

ios后台下载完成但 View 已被破坏

objective-c - 确保我没有在 OSX 上使用任何不可用的 API 的最佳方法是什么?

javascript - jQuery/Javascript if 语句速度

ios - Objective-C 发送按键事件到 webview