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,
- Set delegate to the UITextField
In the delegate method textFieldDidBeginEditing code as follows,
- (void)textFieldDidBeginEditing:(UITextField *)textField { [textField resignFirstResponder]; [pickerView setHidden:NO]; }
精彩评论