2013-04-15 25 views
0

我試圖根據我的UIPickerView中的第一個和第二個選擇輸出某個數字。我在這裏有這個代碼。無法比較我的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"; 
} 

,但我一直沒有得到明顯@interface的錯誤NSMutableArray宣佈選擇objectAtIndex:isequal

我應該如何比較一下兩個值返回?像IF comp(0) == 3 and comp(1) ==2,輸出3.4到我的標籤。

回答

4

這是因爲NSMutableArray沒有「objectAtIndex:isEqual」選擇器。

您需要從選擇器視圖得到的NSString,然後把它比作你存儲在您的NSMutableArray對象的字符串(這大概是高德命名爲「list」和「list2」)。

E.G.

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? 
+0

完美!謝謝! – Intelwalk