填写不同的UITextField具有相同个性化键盘(Fill different UITextFie

2019-10-30 03:07发布

我有在那里我已经不同视图UITextfield 。 为了FIL这个TF我使用的是个性化的UIPickerview键盘。

我的问题是,当我选择第一个TF键盘开放,我可以选择我的价值。 值到这个选择的TF。 现在,当我选择第二个TF键盘出现,但值进入第一个TF ...

我不知道为什么这不工作...

在我ViewDidLoad T've有:

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 ...

谢谢你的帮助 !

Answer 1:

更好的方法是创建一个函数,它接受文本框和标签,创建UIPickerView对象,并设置文本框作为输入视图,同时创造可以分配标签UIPickerView,在委托你可以读日期选取器和更新文本框相应的标签。



文章来源: Fill different UITextField with the same personalised keyboard