【问题标题】:UITableviewCell with UITextField switching between uikeyboard and uidatepickerviewUITableviewCell 和 UITextField 在 uikeyboard 和 uidatepickerview 之间切换
【发布时间】:2011-04-26 16:40:21
【问题描述】:

我有一个包含 3 种行的表。第一种类型包含一个用于字母数字的文本字段,您应该在其中写一些东西。第二种类型应该包含一个带有数字的文本字段。第三种类型包含日期。

我的问题是当我点击第一种类型时,键盘会出现。在类型一和类型二之间切换会立即将键盘从字母数字切换到数字。我怎样才能实现从这些键盘类型立即切换到类型 3 的 uidatepicker。我发现的唯一方法是关闭其他文本字段的键盘并在之后显示一个 uidatepicker。但是关闭键盘会向下滚动键盘。如何实现即时切换?

贝沃

【问题讨论】:

    标签: iphone uitableview uitextfield uipickerview


    【解决方案1】:

    将 UITextField 的 inputView 属性设置为 UIDatePicker 的一个实例。

    picker = [[UIDatePicker alloc] initWithFrame:CGRectZero];
    [picker addTarget:self action:@selector(pickerValueChanged) forControlEvents:UIControlEventValueChanged];
    textField.inputView = picker;
    

    pickerValueChanged中,通过将日期转换为字符串来更新textField的text属性:

    - (void)pickerValueChanged {
        textField.text = [picker.date description];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2010-10-28
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多