0

Inside each of CollectionViewCells i have added UITextField, that need to take input from picker View.

So I'm assigning inputView as pickerView inside my CellForRowAtIndexPath. When i run the code the input view part is empty. Not having any pickerviews.

I realize the datasource methods are not getting invoked.

percentagePicker is created outlet on my ViewController

This is my cellForRowAtIndexPath method

    cell.cropPercent.text = [NSString stringWithFormat:@"%@",cropPercentagesList[indexPath.row];

    UIPickerView *pikerView = _percentagePicker;

    [_percentagePicker removeFromSuperview];

    pikerView.delegate =self;
    pikerView.dataSource = self;

    cell.cropPercent.textColor = [UIColor redColor];

    cell.cropPercent.inputView = pikerView;
Saranjith
  • 11,242
  • 5
  • 69
  • 122

2 Answers2

1

Instead of creating an outlet of UIPickerView and assigning it to the pickerView to show as inputView just try the code below.

    UIPickerView *pikerView = [[UIPickerView alloc]init];

    pikerView.delegate =self;
    pikerView.dataSource = self;

    cell.cropPercent.textColor = [UIColor redColor];

    cell.cropPercent.inputView = pikerView;
Aravind A R
  • 2,674
  • 1
  • 15
  • 25
0

You should move your pickerView code to viewDidLoad since it's in your viewController. Don't create an instance of new UIPickerView;

- (void) viewDidLoad
 {
     [super viewDidLoad];

    _percentagePicker.delegate =self;
    _percentagePicker.dataSource = self;
 }

In your cellForRow just do this and remove other UIPickerView code:

cell.cropPercent.inputView = pikerView;
yourPickerDataSourceArray = yourSource[indexPath.row];
[percentagePicker reloadAllComponents];
NotABot
  • 516
  • 1
  • 8
  • 27