【发布时间】:2011-03-19 16:43:06
【问题描述】:
我有一个方法,只要我的视图上的控件发生更改,它就会被调用,并且应该更新UILabel。它有两个UITextFields 和两个UISliders。首先,我检查UITextFields 中的任何一个是否为空,如果是,建议它们需要填写。否则我得到UITextFields' 值之间的差异并生成几个floats在我的NSStrings 中使用。
我收到一条警告说 message 没有被使用,我收到一个关于 NSStrings 的错误(现在不记得具体是什么了 - 我不在我的 Mac 上...)
即使我将消息简化为简单有效的方法,当delta == 0 时,它也会发送delta <= 0 消息。
哦,字符串不会将值放在 % 符号所在的位置,它们只是打印 % 符号。
我已经破解了太久,需要帮助......
- (void)updateAdvice {
if ([chlorineSourceField.text isEqualToString:@""] || [poolVolumeField.text isEqualToString:@""]) {
NSString *message = [[NSString alloc] initWithString:@"Enter a chlorine source and pool volume."];
}
else {
int delta = [targetLabel.text intValue] - [startingLabel.text intValue];
float chlorineAmount = delta * [poolVolumeField.text intValue] * chlorineConstant;
float percentRemove = (1 - ([targetLabel.text floatValue] / [startingLabel.text floatValue]));
float gallonsRemove = percentRemove * [poolVolumeField.text intValue];
if (delta == 0) {
NSString *message = [[NSString alloc] initWithString:@"No adjustments necessary. You're on target"];
}
if (delta >= 0) {
NSString *message = [[NSString alloc] initWithFormat:@"To increase FC by %dppm, add %3.1f oz of %@.", delta, chlorineAmount, chlorineSourceField.text];
}
if (delta <= 0) {
NSString *message = [[NSString alloc] initWithFormat:@"You're above target already. Replace %d%% or %d gallons of water - or just wait for it to come down.", percentRemove*100, gallonsRemove];
}
}
adviceLabel.text = message;
[message release];
}
【问题讨论】:
标签: iphone xcode nsstring logic if-statement