我正在尝试根据 UIPickerView
中的第一个和第二个选择输出特定数字。我这里有这段代码。
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if([[list objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"1 Gallon"] && [list2 objectAtIndex:[pickerView selectedRowInComponent:1] isEqual: @"Grams"])
output.text = @"1 GALLON GRAMS";
if([[list objectAtIndex:[pickerView selectedRowInComponent:0]] isEqual: @"2 Gallons"] && [list2 objectAtIndex:[pickerView selectedRowInComponent:1] isEqual: @"Ounces"])
output.text = @"2 GALLONS OUNCES";
}
但我不断收到 No visible @interface for NSMutableArray
declares the selector objectAtIndex:isequal
我应该如何比较这两个值的返回值?像 IF comp(0) == 3 and comp(1) ==2
,输出 3.4 到我的标签。
最佳答案
那是因为 NSMutableArray 没有“objectAtIndex: isEqual”选择器。
您需要从选择器 View 中获取 NSString,然后将其与您存储在 NSMutableArray 对象中的字符串进行比较(这些对象可能是名为“list
”和“list2
").
例如
NSString * stringPointedToFromPicker = (NSString *)[list objectAtIndex: [pickerView selectedRowInComponent: 0]];
if([stringPointedToFromPicker isEqual: @"1 Gallon"]) // okay for now, but do you want
output.text = @"1 GALLON GRAMS"; // hard coded, non-localized strings like this?
关于iphone - 无法比较我的 UIPickerView 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16006424/