UIpicker array with changing values
I'm making an app that uses the picker to let the user pick age and few other inputs. for eg: i have a button age, when the user clicks it, the picker shows the age. i managed to add individual picker for all the inputs, how ever开发者_如何学Go i'm having problems setting different arrays for each picker.
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (pickerview == picker) {
return [pickerViewArray objectAtIndex:row];
}
else if (pickerview == stagepicker)
return [stagepickerarray objectAtInde:row];
}
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
if (thePickerView == picker){ return [pickerViewArray count]; }
else if (thePickerView == stagepicker){ [stagepickerarray count]; }
}
the above method isn't working for me !. Am I doing this right ?
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (pickerview == picker) {
Doesn't it sound like pickerview
should be written thePickerView
instead?
return [stagepickerarray objectAtInde:row];
Doesn't it sound like objectAtInde
should be objectAtIndex
?
else if (thePickerView == stagepicker){ [stagepickerarray count]; }
Doesn't it sound like a return
is missing somewhere?
Why not use one UIPickerView with multiple components? Something along the lines of:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSInteger numberOfRows;
if (component == 0) {
numberOfRows = [anArray count];
}
else if(component == 1) {
numberOfRows = [anotherArray count];
}
else {
numberOfRows = [aThirdArray count];
}
return numberOfRows;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *stringIndex = [NSString stringWithFormat:@"TEST"];
if(component == 0) {
return stringIndex = [anArray objectAtIndex:row];
}
else if(component == 1) {
return stringIndex = [anotherArray objectAtIndex:row];
}
else {
return stringIndex = [aThirdArray objectAtIndex:row];
}
return stringIndex;
}
精彩评论