ioscocoa-touchuiviewuipickerviewsetneedsdisplay

UIPickerView doesn't immediately redraw unselected rows


I have a special UIPickerView where a rows is manually selected by tapping on it. When this happens the styling of the selected row changes (text color changes and an image with a check mark is shown). Likewise, if another row is selected, the previously selected row is "deselected", i.e. it's styling changes to normal.

Now, when I select a row it looks correct:

enter image description here

But, when I scroll to another row and the selected row is no longer in the middle its new styling is not applied (Antarktis should be selected here):

enter image description here

However, if I scroll down several rows further and then back up it updates the row to its correct styling:

enter image description here

I have the same issue when deselecting. If I select another row the old row is seemingly not deselected and I get this (Antarktis should be deselected now):

enter image description here

But if I scroll the Antarktis row back in the middle it is indeed deselected. So my issue is that the UIPickerView doesn't immediately redraw the rows that are visible but not in the middle (they are probably cached somehow). They are only redrawn when either the particular row goes out of view and then returns or when completely new rows are shown.

So can I force it to redraw those rows? I have tried calling the setNeedsDisplay method on both the UIPickerView and the specific rows (which are subclasses of UITableViewCell) but it did nothing.

Thank you!


Solution

  • Have you tried calling reloadComponent: or reloadAllComponents on your UIPickerView instance?