I created a UIPickerView manually with three components. I want to display numbers from 1 to 100 in component1. How can I do it programmatically?
I guess you have implemented the methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
and
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
if (component == 1 )
{
return [NSString stringWithFormat:@"%d",(row+1)];
}
return @"";//required elements
}
in .h file
NSMutableArray *data ;
--
data = [NSMutableArray alloc] init];
for (int i=1; i<=100; i++){
[data addObject:[NSString stringWithFormat:@"%d",i];
}
// this will add 1-100 values in your array (data) Then Implement UIPickerViewDelegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [data count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [data objectAtIndex:row];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With