Afficher les données dans UIPickerView deuxième composant basé sur le premier composant de sélection

Je suis à l'aide d'un sélecteur à deux composants. Je veux si je sélectionne une ligne dans le premier volet sur la base de composant sélectionné, il affiche la valeur des données correspondantes.

Afficher les données dans UIPickerView deuxième composant basé sur le premier composant de sélection

Comme sélectionneur est de montrer que l'Angleterre a des correspondants des clubs où l'Angleterre est sélectionné. Je veux faire de même pour les autres pays. Mais je ne suis pas aller de l'approche à suivre.

Voici mon code:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView 
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component 
{
if(component ==0)
{
return [Nations count];
}
else{
if(country_flag==0)
{
return [England count];
}
else if (country_flag==1)
{
return [Espana count];
}
else if (country_flag==2)
{
return [Netherlands count];
}
else if (country_flag==3)
{
return [Germany count];
}
else if (country_flag==4)
{
return [Italy count];
}
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component ==0)
{
return [Nations objectAtIndex:row];
}
else{
if(country_flag==0)
{
return [England objectAtIndex:row];
}
else if (country_flag==1)
{
return [Espana objectAtIndex:row];
}
else if (country_flag==2)
{
return [Netherlands objectAtIndex:row];
}
else if (country_flag==3)
{
return [Germany objectAtIndex:row];
}
else if (country_flag==4)
{
return [Italy objectAtIndex:row];
}
}
return 0;
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
label.text=[Nations objectAtIndex:row];
str = [[NSString alloc]init];
if (country_flag==0) {
str=@"England";
label_1.text=[NSString stringWithFormat:@"%@",str];
NSLog(@"%@",label_1);
str=@"";
country_flag =1;
[picker reloadAllComponents];
}
else if (country_flag==1)
{
str=@"Espana";
label_1.text=[NSString stringWithFormat:@"%@",str];
NSLog(@"%@",label_1);
str=@"";
country_flag =2;
[picker reloadAllComponents];
}
else if (country_flag==2)
{
str=@"Netherlands";
label_1.text=[NSString stringWithFormat:@"%@",str];
NSLog(@"%@",label_1);
str=@"";
country_flag =3;
[picker reloadAllComponents];
}
else if (country_flag==3)
{
str=@"Germany";
label_1.text=[NSString stringWithFormat:@"%@",str];
NSLog(@"%@",label_1);
str=@"";
country_flag =4;
[picker reloadAllComponents];
}
else if (country_flag==4)
{
str=@"Germany";
label_1.text=[NSString stringWithFormat:@"%@",str];
NSLog(@"%@",label_1);
str=@"";
// country_flag =4;
[picker reloadAllComponents];
}
}

EDIT:

Voici les données

Nations = [[NSMutableArray alloc]initWithObjects:@"England",@"Espana",@"Germany",@"Netherlands",@"Germany",@"Italy", nil];
England=[[NSMutableArray alloc]initWithObjects:@"Arsenal",@"Chelsea",@"Manchester City",@"Manchester United",@"Liverpool",@"Tottenham",@"Fulham City",@"Stoke City",@"Sunderland",@"NewCastle United",@"Blackburn Rovers",@"Southampton",@"Wolvers",@"Aston Villa", nil];
Espana = [[NSMutableArray alloc]initWithObjects:@"Barcelona",@"Real Madrid",@"Valencia",@"Athletico Madrid",@"Athletico Balbao",@"Getafe CF",@"Sevilla CF", nil];
Netherlands = [[NSMutableArray alloc]initWithObjects:@"Celtics",@"Ajax",@"Amesterdam", nil];
Germany = [[NSMutableArray alloc]initWithObjects:@"Bayern Munich",@"Bermen",@"Fiorentina",@"Pampas",@"Nord", nil];
Italy = [[NSMutableArray alloc]initWithObjects:@"AC Milan",@"Inter Milan",@"Juventus", nil];
essayez de [sélecteur de reloadComponent:(NSInteger)]; au lieu de [sélecteur de reloadAllComponents];
Merci pour votre soutien de l'homme, mais pas de changement.
Il y a quelque chose de bizarre avec votre country_flag variable. Pouvez-vous nous montrer où elle est déclarée? Aussi, pourquoi doit country_flag == 1 avant que je puisse choisir Espana?
Je l'ai déclaré à country_flag=0 mais je suis en train d'essayer d'augmenter la valeur de l'indicateur dans didSelectRow délégué. Je sais que je vais faire un gâchis, avec des drapeaux, guide-moi un code correct.

OriginalL'auteur DeepK SOreadytohelp | 2012-11-21