Just to clarify, I am not asking how to set the row height once in the beginning when the UIpickerview is being set up. I know you use pickerView:rowHeightForComponent for that purpose.
However, what I am asking is if I want pickerView:rowHeightForComponent to return a variable value, where the value can change during the lifetime of the UIpickerview, e.g., in response to the click of a button or change in a default setting.
I found that, unfortunately, pickerView:rowHeightForComponent is only called once, in the beginning, when iOS is setting up the UIpickerview. After that, it never calls pickerView:rowHeightForComponent again, so can't pick up the change in the value that pickerView:rowHeightForComponent would return if only it were called again.
I suppose I could just release the UIpickerview and set up another one, forcing iOS to call pickerView:rowHeightForComponent again, but this might be inconvenient, and might need saving of state information. Is there another, easier way, to dynamically change the row height? Thanks!
Searching around, I found Changing UIPickerView row height (which is only for the first time setup of the row height) and How to change the size of row in UIPickerView by button click? , which talks about the rowSizeForComponent method, which appears to just use a cached value for the row height.
Here's the portion of code that attempts to change the row height, together with testing reloadAllComponents: as suggested by @RileyE
NSLog(@"before, scrollviewSpacing is %d", self.mainViewController.IACscrollviewSpacing);
if (0.0 != fromDefaultsScrollviewSpacing) {
self.mainViewController.IACscrollviewSpacing = (UInt8) round (60.0 - fromDefaultsScrollviewSpacing);
}
NSLog(@"now scrollviewSpacing is %d", self.mainViewController.IACscrollviewSpacing);
NSLog(@"rowsizeforcomponent height is %f", [self.mainViewController.PickIPAddress rowSizeForComponent:1].height);
[self.mainViewController.PickIPAddress reloadAllComponents];
NSLog(@"rowsizeforcomponent height is %f", [self.mainViewController.PickIPAddress rowSizeForComponent:1].height);
[self.mainViewController.PickIPAddress reloadComponent:1];
NSLog(@"rowsizeforcomponent height is %f", [self.mainViewController.PickIPAddress rowSizeForComponent:1].height);
which gives the following output on the console:
2012-11-29 02:32:14.681 IP Address Calculator[6404:c07] before, scrollviewSpacing is 39
2012-11-29 02:32:18.913 IP Address Calculator[6404:c07] now scrollviewSpacing is 22
2012-11-29 02:32:20.196 IP Address Calculator[6404:c07] rowsizeforcomponent height is 39.000000 2012-11-29 02:32:28.865 IP Address Calculator[6404:c07] rowsizeforcomponent height is 39.000000 2012-11-29 02:32:30.903 IP Address Calculator[6404:c07] rowsizeforcomponent height is 39.000000
and in MainViewController (which is the UIpickerviewdelegate), I have
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
return self.IACscrollviewSpacing; }
Furthermore, I set a breakpoint here, and I see it only gets called when the UIPickerview is initially being set up, and never again.