2014-03-26 6 views
0

나는 (예를 들어) 4 개의 행과 함께 UIPickerView를 사용하고 있습니다. 첫 번째 값은 "값 선택"이며 회색 텍스트입니다. 다른 값은 사용자가 검정 텍스트로 선택해야하는 값입니다.(iOS) UIPickerView에서 첫 번째 값을 선택 취소하는 방법은 무엇입니까?

따기는 선택 사항이므로 건너 뛸 수 있습니다. 하지만 그렇지 않다면, 사용자가 따기를 시작한 후에 어떻게 첫 번째 값을 선택 취소 할 수 없게 만들까요?

감사합니다. 감사합니다.

답변

1

가 선택한 행을 변경합니다 UIPickerView 위임 방법 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component를 사용하여 첫 번째 행이 선택되어있는 경우 :

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 

    if (row == 0) { 
     [pickerView selectRow:row+1 inComponent:component animated:YES]; 
    } 
} 

편집 :

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component { 

    if (row == 0) 
     return [[NSAttributedString alloc] initWithString:@"Pick a value" attributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]}]; 
    else { 
     // Return titles 
    } 
} 
: 당신은이를 사용하여 텍스트 색상을 변경할 수 있습니다

iOS 6 이상을 타겟팅하고 이전에 사용 된 -pickerView:titleForRow:forComponent: 메소드를 대체합니다.

+0

작동합니다. 한 가지 더 질문 - 방법에서 회색으로 만드는 방법? 한 줄의 맞춤 텍스트와 색상을 만드는 방법은 무엇입니까? – Palindrome

+0

@Palindrome :이 질문을 편집했습니다. – rdurand