Legolas
Legolas

Reputation: 12325

UIPickerView not connecting to the DataSource

So my UIPickerView does not get connected to the DataSource. I Have no idea WHY.

I create a file with UIPickerViewDelegate and UIPickerViewDataSource, and properly do the procedure for bringing a UIPickerView on tapping a textField.

The pickerView works , but does not show any component. I have implemented

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}

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



- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 


- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 


- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

Any idea why the pickerView is not getting connected to the DataSource ? I also tried NSLogging inside all these methods. // Does not print

I had also set

packSizePopPickerView.delegate = self;
packSizePopPickerView.dataSource = self;
packSizePopPickerView = [[UIPickerView alloc] init];

Upvotes: 0

Views: 2426

Answers (2)

thomashw
thomashw

Reputation: 956

In cellForRowAtIndexPath, you're setting packSizePopPickerView's dataSource/delegate, and THEN allocating/initializing packSizePopPickerView to a new UIPickerView. The NEW UIPickerView no longer has its delegate/dataSource set.

This is WRONG:

packSizePopPickerView.delegate = self;
packSizePopPickerView.dataSource = self;
packSizePopPickerView = [[UIPickerView alloc] init];

Try this:

packSizePopPickerView = [[UIPickerView alloc] init];
packSizePopPickerView.delegate = self;
packSizePopPickerView.dataSource = self;

Upvotes: 1

Dancreek
Dancreek

Reputation: 9544

You need to explicitly tell the picker what its data sources and delegates are.

myPicker.delegate = someController; myPicker.datasource = someController;

Upvotes: 0

Related Questions