CAN
CAN

Reputation: 1717

Selecting first row in UIPickerView issue

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
}

Upvotes: 2

Views: 5413

Answers (2)

suchit kushwaha
suchit kushwaha

Reputation: 11

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

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

Upvotes: 1

Jatin Patel - JP
Jatin Patel - JP

Reputation: 3733

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.

Upvotes: 9

Related Questions