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

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

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

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

知道怎么做吗?

【问题讨论】:

  • 我猜你会数零的个数。
  • 你确定这个问题表达了你想问的问题吗?

标签: objective-c cocoa-touch user-interface alerts


【解决方案1】:

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

  1. 查找错误
  2. 显示警报

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

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];   
}

【讨论】:

    猜你喜欢
    • 2013-03-28
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 2016-02-03
    • 1970-01-01
    • 2015-05-02
    相关资源
    最近更新 更多