我认为我的UITextfield
与众不同。要过滤此TF,我使用个性化的UIPickerview
作为键盘。
我的问题是,当我选择First 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
}()
我现在不该如何与我的代表打交道以填补合适的TF ...
感谢您的帮助!
答案 0 :(得分:0)
更好的方法是创建一个使用文本字段和标签的函数,创建UIPickerView对象并设置为文本字段的输入视图,同时创建时可以将标签分配给UIPickerView,在委托中您可以读取日期选择器的标签并相应地更新文本字段。