在 Xcode 中检查多个变量值

Posted

技术标签:

【中文标题】在 Xcode 中检查多个变量值【英文标题】:Checking for multiple variable value in Xcode 【发布时间】:2012-03-10 14:15:28 【问题描述】:

我正在创建一个 iPhone 应用程序,它从用户那里获取许多值并将它们分配给变量。

如果两个以上的变量值为零,我想显示一条警告消息。

基本上,如果用户有两个空字段,它应该显示一个警告,指出数据不足。

知道怎么做吗?

【问题讨论】:

我猜你会数零的个数。 你确定这个问题表达了你想问的问题吗? 【参考方案1】:

你的问题有点含糊,但是呢

    查找错误 显示警报

这个伪代码的行单独的地方:

int errorCount = 0;

if(var1 == 0) 
    errorCount++;


if(var2 == 0) 
    errorCount++;


// check all variables...

// Show alert if there are any errors
if(errorCount > 0) 
    UIAlertView *alert = [[UIAlertView alloc]
              initWithTitle:@"Title"
              message:[NSString stringWithFormat:@"You have %d errors", errorCount]
              delegate:nil
              cancelButtonTitle:@"GoFightWin"
              otherButtonTitles: nil, nil];
    [alert show];
    [alert release];   

【讨论】:

以上是关于在 Xcode 中检查多个变量值的主要内容,如果未能解决你的问题,请参考以下文章