How to resize a string in a UIPickerView with the click of a button?

I tried to do it this way: call reloadAllComponents: when the button is pressed, but it does not call rowHeightForComponent:

+1
source share
3 answers

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

Instead, I would try calling rowSizeForComponent: for each component. The documentation for this method says: "Returns: row size in this component. Usually this is the size needed to display the largest row or view used as a row in the component. The select view selects the value of this property by calling pickerView: widthForComponent: and pickerView: rowHeightForComponent: delegate methods and cache it. The default value is (0, 0). "

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

+1
source

You do not need to free pickerView to set a new cell height, e.g. @auspicious99 . Instead, set a delegate or data source each time you run reloadAllComponents as follows:

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

It is really strange why the reloadAllComponents methods do not start the rowHeightForComponent method, but this seems to be a valid workaround using the trick above.

Hope this helps.

+1
source

You may need to free UIpickerview and create another one with the corresponding return value in pickerView: rowHeightForComponent:

It sounds like pain, but I can't think of another solution.

Unfortunately, it seems that calling rowSizeForComponent will not help, because, as the docs say, "the select view selects the value of this property by calling pickerView: widthForComponent: and pickerView: rowHeightForComponent: delegate methods and cache it." Thus, calling rowSizeForComponent provides only cached values, not calling pickerView: rowHeightForComponent: to get a new value.

0
source

All Articles