I am using a picker with two components. I want if I select a row in first component on the basis of selected component it shows the value of the corresponding data.
your code.. with minor modifications..
didSelectRow
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (component == 0) {
club=[[NSString alloc] initWithFormat:@"%@" , [Nations objectAtIndex:row]];
[pickerView reloadComponent:1];
}
}
after that...
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
if(component ==0)
{
return [Nations count];
}
else {
if ([club isEqualToString:@"Espana"]) {
return [Espana count];
}
if ([club isEqualToString:@"Germany"]) {
return [Germany count];
}
// if...
else {
return [England count];
}
}
return 0;
}
and
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if(component ==0)
{
return [Nations objectAtIndex:row];
}
else {
if ([club isEqualToString:@"Espana"]) {
return [Espana objectAtIndex:row];
}
if ([club isEqualToString:@"Germany"]) {
return [Germany objectAtIndex:row];
}
//if....
else {
return [England objectAtIndex:row];
}
}
return 0;
}
UPD
in h file I have
@interface ViewController : UIViewController {
IBOutlet UIPickerView *pickerView;
NSMutableArray *arrayColors;
NSMutableArray *Nations;
NSMutableArray *England;
NSMutableArray *Espana;
NSMutableArray *Germany;
NSString *club;
}
after that.. you must connect de pickerView to yours ViewController (dataSource and delegate)
