1

I tried to do it in this way: call reloadAllComponents: when button is clicked but it doesnt call rowHeightForComponent:

Bogdan
  • 1,286
  • 9
  • 12
  • one way is redifine delegate and dataSource in button selector `self.pickerView.delegate = self;` `self.pickerView.dataSource = self;` but I dont know is it normal :) – Bogdan Apr 26 '12 at 10:12

3 Answers3

1

From the documentation, it looks like reloadAllComponents: just calls the delegate for new data inside the components, but presumably doesn't ask for the size.

Instead, I would try calling rowSizeForComponent: on each component. In the documentation for this method, it says, "Returns: The size of rows in the given component. This is generally the size required to display the largest string or view used as a row in the component. A picker view fetches the value of this property by calling the pickerView:widthForComponent: and pickerView:rowHeightForComponent: delegate methods, and caches it. The default value is (0, 0)."

Then, in your UIPickerViewDelegate, I would implement both pickerView:widthForComponent: and pickerView:rowHeightForComponent:.

Chris Livdahl
  • 4,662
  • 2
  • 38
  • 33
  • I mean that I need to change the size of row then I click the button that is on the same View as PickerView. – Bogdan Apr 26 '12 at 11:39
  • So, can you do that by having a method that fires when the button is clicked, and inside that method calling rowSizeForComponent on each component? Assuming you have an array of components to walk through... – Chris Livdahl Apr 26 '12 at 19:39
1

You don't need to release pickerView to set new cell height like @auspicious99 proposed. Instead set the delegate or dataSource each time you trigger reloadAllComponents like this:

pickerView.delegate = self; //or pickerView.dataSource = self;
[pickerView reloadAllComponents];

It's really strange why reloadAllComponents methods doesn't trigger rowHeightForComponent method, but this looks like to be a valid workaround using above trick.

Hope it helps.

Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91
0

You might need to release the UIpickerview and create another one with the appropriate return value in pickerView:rowHeightForComponent:

This seems like a pain, but I can't think of another solution offhand.

Unfortunately, it seems that calling rowSizeForComponent won't help, because, as the docs say, "A picker view fetches the value of this property by calling the pickerView:widthForComponent: and pickerView:rowHeightForComponent: delegate methods, and caches it." So, calling rowSizeForComponent only provides the cached values, rather than calling pickerView:rowHeightForComponent: to pick up the new value.

auspicious99
  • 3,902
  • 1
  • 44
  • 58