Eric Wong
Eric Wong

Reputation: 524

How to change the number of components in a UIPickerView?

I have a UITableView for different datas. When the user select one row, then I will popup a UIPickerView to let the user select some values. And I have implemented the numberOfComponentsInPickerView DataSource method to return the number of components for different row in the UITableView. actually they are all 1.

But now, I will download more data from the internet and add more rows in the UITableView. I called [pickerView reloadAllComponents] after finishing the downloading. I expected the numberOfComponentsInPickerView will be called so I can have more components in the picker view for the new rows in UITableView. But it's not working.

How can I do that? thanks.

Upvotes: 2

Views: 3859

Answers (2)

Alan Keele
Alan Keele

Reputation: 231

In XCode 4.2 running on an IOS 5 device, I was able to get [pickerView reloadAllComponents] to change the number of components in a UIPickerView.

It works exactly as you originally expected it to. Calling reloadAllComponents caused the numberOfComponentsInPickerView method to get called.

Upvotes: 5

Eric Wong
Eric Wong

Reputation: 524

I found a solution for my problem. Instead of trying to make the UIPickerView reload and change the number of components dynamically, I use two UIPickerView, one has 1 component, and the other has two. And I will switch between these two when the user select different rows of data in the tableview.

Hope this can help if other people has similar need.

Upvotes: 1

Related Questions