gpt4 book ai didi

swift - 使用相同的个性化键盘填充不同的UITextField

转载 作者:行者123 更新时间:2023-11-30 10:48:04 24 4
gpt4 key购买 nike

我有一个 View ,其中有不同的UITextfield。为了填充这个 TF,我使用个性化的 UIPickerview 作为键盘。

我的问题是,当我选择第一个 TF 时,键盘打开,我可以选择我的值。该值将转到该选定的 TF。现在,当我选择第二个 TF 时,键盘会出现,但值会转到第一个 TF ...

我不知道为什么这不起作用......

在我的ViewDidLoad中得到:

flightTimeSe.inputAccessoryView = Ttoolbar
flightTimeSe.delegate = self
flightTimeMe.inputView = DurationPicker
flightTimeMe.inputAccessoryView = Ttoolbar
flightTimeMe.delegate = self
flightTimeMp.inputView = DurationPicker

这会将 UIPickerview 分配给 TF 和我的工具栏。

我的UIPickerview定义如下:

lazy var DurationPicker: UIPickerView = {
let DurationPicker = UIPickerView()
DurationPicker.delegate = self
DurationPicker.dataSource = self

var flightTime: String = ""
var row0: String = "0"
var row1: String = "0"
var row2: String = "0"
var row4: String = "0"
var row5: String = "0"

row0 = myPickerRow1[DurationPicker.selectedRow(inComponent: 0)]

row1 = myPickerRow2[DurationPicker.selectedRow(inComponent: 1)]

row2 = myPickerRow3[DurationPicker.selectedRow(inComponent: 2)]

row4 = myPickerRow5[DurationPicker.selectedRow(inComponent: 4)]

row5 = myPickerRow6[DurationPicker.selectedRow(inComponent: 5)]

//print("\(row0)\(row1)\(row2):\(row4)\(row5)")

if row0 != "0"{
flightTime = "\(row0)\(row1)\(row2):\(row4)\(row5)"
}else if row0 == "0" && row1 != "0" {
flightTime = "\(row1)\(row2):\(row4)\(row5)"
}else if row1 == "0" && row2 != "0" {
flightTime = "\(row2):\(row4)\(row5)"
}else if row2 == "0" && row4 != "0" {
flightTime = "\(row2):\(row4)\(row5)"
}else if row2 == "0" && row4 == "0" && row5 != "0" {
flightTime = "\(row2):\(row4)\(row5)"
}
print(flightTime)
return DurationPicker
}()

我现在不知道如何处理我的委托(delegate)来填补正确的 TF...

感谢您的帮助!

最佳答案

更好的方法是创建一个函数,它接受文本字段和标签,创建 UIPickerView 对象并设置为文本字段的输入 View ,在创建时您可以将标签分配给 UIPickerView,在委托(delegate)中您可以读取日期选择器的标签并相应地更新文本字段。

关于swift - 使用相同的个性化键盘填充不同的UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55354059/

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