2010-04-14 5 views

답변

2

내가 한 것은 touchesEnded 이벤트를 구현 한 것입니다. 해당 이벤트 내 UITextField에 매개 변수에서 발생하는 경우 I 중 하나를 숨기거나 내가 정확히이 일을 내 블로그에 배치 코드와 모든 것을 가지고있는 UIPickerView

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{  
    UITouch *touch = [[event allTouches] anyObject]; 

    if (CGRectContainsPoint([self.textField frame], [touch locationInView:self.view])) 
    { 
     //Want to show or hide UIPickerView 
     if(pickerView) 
     { 
      submitButton.hidden = !submitButton.hidden; 
      pickerView.hidden = !pickerView.hidden; 
     } 
    } 
} 
2

NSTextField있는 위임 방법에있을 것입니다 그렇게 할 수있는 가장 좋은 장소 :

- (BOOL)textShouldBeginEditing:(NSText *)textObject

재정 NO를 반환하는 대신 피커보기를 연상 할 수있는 방법. NO를 반환하면 키보드가 나타나지 않습니다.

+2

나는 이것이 같아야한다고 생각한다 : - (BOOL) textFieldShouldBeginEditing : (UITextField *) textField – Kurt

+0

당신 말이 맞아요. API가 잘못되었습니다. – TechZen

0

http://tmblr.co/ZjkSZteCOUBS

을 보여줍니다. 하지만 아래에는 기본적인 개념이 있습니다.

기본적으로이 솔루션은 github의 ActionSheetPicker라는 오픈 소스 프로젝트와 관련되어 있으며 을 UITextFieldDelegate에 구현합니다. 거기에서 키보드를 닫고 대신 UIPickerView를 제공 할 수 있습니다. 나는이 질문에 얼마 전에 질문을 받았다 알고

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    // We are now showing the UIPickerViewer instead 

    // Close the keypad if it is showing 
    [self.superview endEditing:YES]; 

    // Function to show the picker view 
    [self showPickerViewer :array :pickerTitle]; 

    // Return no so that no cursor is shown in the text box 
    return NO; 
} 

편집을하지만, 좀 더 최근의 솔루션을 제공하는 것이 필요하다고 생각 : 기본 코드는 여기에 나열됩니다.

+0

댓글을 달았을 때 답변을 업데이트하는 중이었습니다 :) – KVISH

+0

Excellent; 감사! –