I have a UIPickerView where the numberOfComponentsInPickerView=4. But how do I populate each component, as they have different v开发者_如何转开发alue ranges?
Thanks
by implementing – pickerView:numberOfRowsInComponent:
of the pickers datasource.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 4;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0){
return 5;
} else if (component == 1){
return 3;
} else if (component == 2){
return 10;
} else if (component == 3){
return 5;
}
return 0;
}
and the pickerView's delegate
either – pickerView:titleForRow:forComponent:
or – pickerView:viewForRow:forComponent:reusingView:
If the components change, you can call [aPickerView reloadComponent:<numberOfComponent>]
or [aPickerView reloadAllComponents]
if even the number of components changes.
The dataSource and the viewDelegate documentation.
edit
I just put my very first iPhone program on GitHub, that is a coffee configuration based on a 3 or 4 component picker: You can select amount, kind and one option for every coffee. Except for Latte — there you can choose two different options. You will find it in this repository as "M18Coffee". As I said: my very first program — might be rough.
精彩评论