2010-12-13 1 views
1

Je dois afficher une liste déroulante dans mon application.Obtenir une confusion avec la façon d'ouvrir Deux valeurs de tableau pour les événements de clic à deux boutons dans la vue UIPicker

la plupart d'entre eux me suggèrent UIPickerView pour la liste déroulante.

Mais mon exigence est que je dois placer deux boîtes déroulantes dans mon application.

mon code pour une vue UIPicker est

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { 

    return 1; 
} 

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { 

    return [arrayColors count]; 
} 

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 

    return [arrayColors objectAtIndex:row]; 
} 

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 

    NSLog(@"Selected Color: %@. Index of selected color: %i", [arrayColors objectAtIndex:row], row); 
} 



- (IBAction)dropdown_term_in_years: (id)sender 
{ 
    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Ratings" 
                 delegate:self 
              cancelButtonTitle:@"OK" 
             destructiveButtonTitle:nil 
              otherButtonTitles:nil]; 

    UIPickerView *pickerView = [[UIPickerView alloc] init]; 
    //pickerView.datePickerMode = UIDatePickerModeDate; 
    pickerView.showsSelectionIndicator = YES; 
    pickerView.dataSource = self; 
    pickerView.delegate = self; 

    [menu addSubview:pickerView]; 
    [menu showInView:self.view]; 
    [menu sendSubviewToBack:pickerView];  
    [menu setBounds:CGRectMake(0,0,320, 300)]; 

    CGRect pickerRect = pickerView.bounds; 
    //pickerRect.origin.y = -100; 
    pickerView.bounds = pickerRect; 

    [pickerView release]; 
    [menu release]; 
} 

cela fonctionne pour un seul bouton clic, je dois ouvrir un autre tableau de valeurs pour le bouton un autre clic.

comment puis-je faire cela.

PLs m'aident.

Merci d'avance.

Répondre

1

Je pense que vous avez besoin d'une attribution de tag pour toutes les vues du sélecteur. Attribuez deux étiquettes différentes pour les deux vues du sélecteur.

Maintenant, obtenez simplement une balise de l'argument PickerView et effectuez l'action correspondante dans le délégué. i.e. - (NSInteger) pickerView: (UIPickerView *) thePickerView numberOfRowsInComponent: composant (NSInteger) { interrupteur (thePickerView.tag) { cas 101: retour [arrayImage compte]; case 102: return [nombre de couleurs du tableau]; } }

Questions connexes