【问题标题】:Checking for multiple variable value in Xcode在 Xcode 中检查多个变量值
【发布时间】:2012-03-10 14:15:28
【问题描述】:
我正在创建一个 iPhone 应用程序,它从用户那里获取许多值并将它们分配给变量。
如果两个以上的变量值为零,我想显示一条警告消息。
基本上,如果用户有两个空字段,它应该显示一个警告,指出数据不足。
知道怎么做吗?
【问题讨论】:
标签:
objective-c
cocoa-touch
user-interface
alerts
【解决方案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];
}