2014-04-02 1 views
1

두 개의 피커 뷰 p1과 p2가 있고 p1 데이터가 파싱 된 후 p2 값이 p1에서 선택한 값에 따라 달라 지므로 p2 값이 변경됩니다 매번 p1에서 다른 값을 선택하고 p2에서 값이 오는 것은 파싱 후에도옵니다. 그래서 나는 p1에서 선택된 값의 이름과 이드가 필요합니다. 그리고 텍스트 상자에 쓰여진 이름을받을 때 이름을 얻었지만 문제는 이름에 따라 ID를 가져 오는 방법입니다.다른 pickerview의 값 선택에 따라 pickerview의 값을 변경합니다.

+0

데이터베이스에서 "where"키워드를 사용할 수 있습니까? arr = [[dict objectforkey : @ "id"] 여기서]; – Ricky

답변

2

p2의 경우 titleForRow은 (a) p1에서 선택된 행을 식별해야합니다. (b)는 p2row 매개 변수를 사용하여 타이틀을 리턴 할 문자열을 식별하는 것을 사용

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    if (pickerView == self.p1) { 
     // do whatever you're doing for p1 
    } else if (pickerView == self.p2) { 
     NSInteger p1Row = [self.p1 selectedRowInComponent:0]; 

     // now lookup identifier in `p1` associated with row `p1Row` 

     // now that you have the identifier for `p1`, now look up the text strings 
     // for `p2` on the basis of (a) that identifier; and (b) the `row` number 
     // passed to this method 

     return ...; // now return the title 
    } 

    return nil; 
} 

물론, 당신이 p1에서 선택을 변경하는 경우, 당신은 다음 p2을 다시로드 할 수 있습니다. 당신 피커 뷰를 백업 모델에

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
    if (pickerView == self.p1) { 
     [UIView transitionWithView:self.p2 duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ 
      [self.p2 reloadAllComponents]; 
      [self.p2 selectRow:0 inComponent:0 animated:NO]; 
     } completion:nil]; 
    } 
} 

불행하게도, 특정 코드 세부 사항은 따라 달라집니다,하지만 희망이 기본적인 아이디어를 보여 다음은 전환이 덜 부조화하기 위해, 빠른 페이드 전환을한다.

관련 문제