我已经从核心数据集中提取了数据,现在想对数组中Strings表示的值求和。以下代码可以正常工作,但只能拾取遇到的第一个值,如何使它循环并拾取存储在数组中的其他值?
if([rainResults count] == 0) {
rainfallTotal = @"No rainfall recorded";
}
else {
for (NSManagedObject *mo in rainResults) {
rainfallAmount = [mo valueForKey:@"gauge"];
rainSum = [rainfallAmount floatValue];
NSString *intTotal = [NSString stringWithFormat:@"%f", rainSum];
rainfallTotal = [intTotal stringByAppendingString:unitsString];
}
}
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc] initWithTitle:@"Rainfall" message:pickedGauge delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Total year to date", rainfallTotal, nil];
alertDialog.alertViewStyle = UIAlertViewStyleDefault;
[alertDialog show];
看起来好像您遍历了OK,但是看起来不是真的将这些解析值加在一起了?
IE。我本以为您的降雨线是这样的:
rainSum += [rainfallAmount floatValue];
您确定只看到FIRST值而不是LAST吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句