开发者

How to set UITextField setInputView to UIPickerView - iphone OS:3.1.2

开发者 https://www.devze.com 2023-03-25 05:49 出处:网络
I have created a UITextField along with UIPickerView programmatically and set the input view of the text field to picker view but when i upload this test application to the iphone test device with iPh

I have created a UITextField along with UIPickerView programmatically and set the input view of the text field to picker view but when i upload this test application to the iphone test device with iPhone OS: 3.1.2 it crashes on [textfield setInputView:picker] executio开发者_StackOverflown, however the same test application works fine if uploaded on iphone test device with iphone OS: 4.1. Please let me know how could i make it work on iphone OS:3.1.2

Thanks

UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f, 480.0f, 320.0f, 270.0f)];
picker.delegate = self;
[TestViewController addSubview:picker]; 

UITextField* textfield = [[UITextField alloc] initWithFrame:CGRectMake(145.0f, 97.0f, 155.0f, 29.0f)];
textfield.delegate = self;

[textfield setInputView:picker];    // Crashes on execution
[TestViewController addSubview:textfield];


setInputView is Available in iOS 3.2 and later..

To achieve this in iOS 3.1.2,

  1. Set delegate to the UITextField
  2. In the delegate method textFieldDidBeginEditing code as follows,

    - (void)textFieldDidBeginEditing:(UITextField *)textField
    {
    [textField resignFirstResponder];
    [pickerView setHidden:NO];
    }
    
0

精彩评论

暂无评论...
验证码 换一张
取 消