最初我想在选择 UITableViewCell 或 UILabel 时实现一个选择器。
最好的方法是 1. 继承 UItextfield 并将其 inputView 设置为选择器。 2. 使该文本字段成为 didSelectRowAtIndexPath 中的 FirstResponder
在下面回答
最佳答案
inputView
属性用于将选择器 View 分配给 TextField 的第一响应者。它不会显示 PickerView。因此,WarmUpTextField.inputView = Picker
应该移动到 viewDidLoad()
。
您在 didSelectRowAtIndexPath
中期望的是将 TextField 设置为第一响应者。下面这个函数的代码应该可以如你所料的那样工作。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 0 {
NameTexField.becomeFirstResponder()
} else if indexPath.section == 1 {
WarmUpTextField.becomeFirstResponder()
}
}
关于ios - UIPicker 作为 UITextfield 键盘的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29086815/