检查Xcode中的多个变量值
问题描述:
我正在创建一个iPhone应用程序,它从用户获取许多值并将它们分配给变量。检查Xcode中的多个变量值
如果超过两个变量的值等于零,我想显示一条警报消息。
基本上,如果用户有两个空字段,它应该显示一个警报,说明没有足够的数据。
任何想法如何做到这一点?
答
你的问题有点含糊,但怎么样
- 查找错误
- 显示一个警告
某处单独的这个伪代码行:
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];
}
我猜你会计算零的数量。 – 2012-03-10 14:18:28
你确定这个问题传达了你想问的问题吗? – 2012-03-10 15:07:45