Why isn't the UIPickerView widthForComponent delegate method called everytime the view appears?

帅比萌擦擦* 提交于 2019-12-02 05:50:22

It turns out that if you reset the picker's delegate, the component widths are redrawn each time a selection is made. The modified code looks like this:

-(void)viewWillAppear:(BOOL)animated {

 ....

 self.PopulatePickerArray; // Populate components based on selection

 sizePicker.delegate = nil; // NEW CODE
 sizePicker.delegate = self; // NEW CODE

 [picker reloadAllComponents];

}

Found info on this web page - Changing-Width-UIPicker-Continually

Actually, just using setNeedsLayout will also work and might be a bit cleaner.

[picker reloadAllComponents];
[picker setNeedsLayout];

I am not sure, but you can try to call [pickerView reloadAllComponents]; in your viewWillAppear method.

  if(currentNumbersOfComponents < 4){
    currentNumbersOfComponents++;
    [picker reloadAllComponents];
}

The numberOdComponents method returns currentNumberOfComponents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!