gpt4 book ai didi

ios - UIPickerView - 不适用于 UITextView TouchUp

转载 作者:可可西里 更新时间:2023-11-01 01:59:53 24 4
gpt4 key购买 nike

我有一个包含三个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com