2013-04-15 2 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"; 
} 

하지만 NSMutableArray에 대한 가시적 @ 인터페이스의 오류가 계속이 두 값이 무엇을 반환하는 objectAtIndex:isequal

가 어떻게 비교해야 선택기를 선언? IF comp(0) == 3 and comp(1) ==2처럼 내 라벨에 3.4을 출력하십시오.

답변

4

NSMutableArray에는 "objectAtIndex : isEqual"선택자가 없기 때문에 그 때문입니다.

선택기보기에서 NSString을 가져온 다음 NSMutableArray 객체 ("list"및 "list2"이라는 이름의이 ivars)에 저장 한 문자열과 비교해야합니다.

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

관련 문제