0

我正在尝试根据我的第一个和第二个选择输出某个数字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 NSMutableArrayDeclarations the selectors的错误objectAtIndex:isequal

我应该如何比较这两个值返回的内容?像IF comp(0) == 3 and comp(1) ==2,输出 3.4 到我的标签。

4

1 回答 1

4

那是因为 NSMutableArray 没有 "objectAtIndex: isEqual" 选择器。

您需要从您的选择器视图中获取 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?
于 2013-04-15T01:40:16.400 回答