Fill different UITextField with the same personalised keyboard

旧城冷巷雨未停 提交于 2020-01-25 08:44:25

问题


I've got a view where I've different UITextfield. To fil this TF I use a personalised UIPickerview as keyboard.

My problem is, when I select the First TF the keyboard open and I can select my value. The value go to this selected TF. Now when I select the second TF the keyboard appears but the value goes to the first TF ...

I don't know why this not works ...

In my ViewDidLoad T've got :

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

This assign the UIPickerviewto the TF and Also my toolbar.

My UIPickerview is defined as follow :

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
    }()

I don't now how to deal with my delegate to fill the right TF...

Thanks for your help !


回答1:


Better approach is create a function which takes textfield and tag, creates UIPickerView object and set as input view of textfield, while creating you can assign tag to UIPickerView, in delegate you can read tag of date picker and update textfield accordingly.



来源:https://stackoverflow.com/questions/55354059/fill-different-uitextfield-with-the-same-personalised-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!