作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个包含三个 UITextView 的表单。我想在点击文本字段时显示一个 UIPickerView。我已经为它写了下面的代码-
@IBAction func selectServiceBook(_ sender: UITextField) {
let message = "\n\n\n\n\n\n"
let alert = UIAlertController(title: "Select Service Book", message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.isModalInPopover = true
let pickerFrame = UIPickerView(frame: CGRect(x: 20, y: 20, width: 200, height: 140)) // CGRectMake(left, top, width, height) - left and top are like margins
pickerFrame.tag = 666
//set the pickers datasource and delegate
pickerFrame.delegate = self
//Add the picker to the alert controller
alert.view.addSubview(pickerFrame)
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
(alert: UIAlertAction!) -> Void in
self.ServiceBook.text = self.selectedServiceBook
})
alert.addAction(okAction)
self.present(alert, animated: true, completion: {
self.ServiceBook.text = self.selectedServiceBook
})
}
这会完成两个字段的工作,但在点击 ServiceBook 时,键盘会打开,而不是选择器 View 。当我点击屏幕上的其他任何地方时,会弹出选择器 View 。所以我的假设不是 EditingDidBegin,而是指 EditingDidEnd 事件。
我如何检查并确认?
最佳答案
这里是例子
let myPickerProject = [ "Project 1", "Project 2", "Project 3", "Project 4", "Project 5", "Project 6"] // to feed row
pickerProject.delegate = self
let pickerProject = UIPickerView()
let txtFiled = UITextField.init(frame: <#T##CGRect#>)
txtFiled.inputView = pickerProject
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView( _ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return myPickerProject.count
}
func pickerView( _ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return myPickerProject[row]
}
func pickerView( _ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let selectedvalue = myPickerProject[row]
}
关于ios - UIPickerView - 不适用于 UITextView TouchUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47565152/
我是一名优秀的程序员,十分优秀!