解决方法
确保您的类实现了
UITextFieldDelegate
协议.然后,覆盖shouldBeginEditing委托方法以返回FALSE:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { //check if it is the UITextField you don't want the keyboard for if (textField != dateTextField) return TRUE; //present your UIDatePicker //see instructions below //Return false to prevent the keyboard from appearing. return FALSE; }
我建议使用另一个包含UIDatePicker的UIViewController并使用presentModalViewController来显示它.这符合用户界面指南.