Search code examples
iosuipickerview

How many times should one implement the same datasource protocol method for UIPickerView


If I have 2 pickers in the same viewcontroller, how many times should I implement this method:

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component

Solution

  • You can only implement a given method once in a single class. If you want to support two pickers with a single controller, just have the delegate methods look at the thePickerView parameter, which tells you which picker is asking for data.