Selecting first row in UIPickerView issue

依然范特西╮ 提交于 2019-12-10 11:25:50

问题


I've a many textfield and a pickerView with toolBar and it has a done button. My issue is I can't select the first row from the picker. While I have debugged in the didSelectRow but it won't run inside it. So please where would be my issue?

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    var value = currentPickerArray[row]
    textFieldOutletArray[currentTag].text = value
}

回答1:


Just replace didSelect method in your sample code like as bellowed. it will working fine.

@IBAction func doneBtn(sender: AnyObject) {

        var row = pickerView.selectedRowInComponent(0);
        NSLog("value L %d", row)
        pickerView(pickerView, didSelectRow: row, inComponent:0)
    }

Hope this help you.




回答2:


In the titleForRow function add this line of code. It shows first row selected:

textField.text = pickerArray.objectAtIndex(row).objectForKey("Name") as? String


来源:https://stackoverflow.com/questions/31206213/selecting-first-row-in-uipickerview-issue

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