How to set data for UIPickerView?
1 answer
Implement the UIPickerViewDataSource methods :
– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:
and UIPickerViewDelegate :
– pickerView:titleForRow:forComponent:
Don't forget to set properties:
UIPickerView * myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
myPickerView.delegate = self;
myPickerView.dataSource = self;
[self.view addSubview:myPickerView];
And in the .h file, don't forget to put:
<UIPickerViewDelegate, UIPickerViewDataSource>
I usually use NSMutableArray
filled with strings to fill in the data. Hope it helps!
+5
source to share