user5932360
user5932360

Reputation:

UIPickerView Jitter

I have a UIPickerView and a UILabel, separate from each other.

When the user selects a row in the UIPickerView, I change the UILabel text using the delegate function:

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
    label.text = String(row);
}

Yet for some reason changing the label's text causes the UIPickerView to jump back to the top (first row).

When I remove the line "label.text = String(row);" the UIPickerView does not jump at all.

This is very strange and I can't find any correlation between the two elements.

Thank you in advance for any replies :)

Upvotes: 1

Views: 108

Answers (1)

user5932360
user5932360

Reputation:

Turns out that this "strange magical bug" was due to the fact that I set the UIPickerViews's default value in viewDidLayoutSubviews() due to another bug.

Therefore whenever an element was changed, viewDidLayoutSubviews() was called and the UIPickerView's value was set again, causing it to jump.

Upvotes: 0

Related Questions