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

前端 未结 3 1859
慢半拍i
慢半拍i 2021-01-25 08:19

I\'ve got two controls on an iPhone screen - a TableView and a UIPickerView. When you select the single cell in the TableView you\'re taken to another screen where you\'re show

相关标签:
3条回答
  • 2021-01-25 08:30

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

    [picker reloadAllComponents];
    [picker setNeedsLayout];
    
    0 讨论(0)
  • 2021-01-25 08:33

    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

    0 讨论(0)
  • 2021-01-25 08:34

    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

    0 讨论(0)
提交回复
热议问题