ios UITextField 使用 uidatepicker 进行编辑

标签 ios uiviewcontroller uitextfield editing uidatepicker

我有一个写有日期的 uitextfield.. 我怎样才能在页面底部显示一个 uidatepicker 而不是标准键盘? 提前致谢

最佳答案

确保你的类实现了UITextFieldDelegate协议(protocol)。然后,覆盖 shouldBeginEditing 委托(delegate)方法以返回 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;
}

我建议使用另一个包含 UIDatePickerUIViewController 并使用 presentModalViewController 来显示它。这符合用户界面指南。

关于ios UITextField 使用 uidatepicker 进行编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4729723/

相关文章:

ios - 如何在 UITextField 中只允许数字和字母没有任何空格且正好是 8 个字符

ios - 如何提取从 Eureka Forms 解析的值?

IOS Swift 从谷歌地图中删除首都

ios - 普通 View Controller 内的 TableView

ios - Pushcontroller 类似于呈现 View Controller 的过渡

iphone - 以编程方式在 UiTextField 中移动光标

ios - 子类化文本字段时,语言环境不会从 Storyboard 中获取

ios - 如何清理 Storyboard Segues 创建的 UIViewController 实例?

ios - 无法从 for 循环调用方法

iphone - 从扩展调用 UIViewController 中的函数