getting confusion with how to open Two array values for Two Button click events in UIPicker view
I need to display drop down box in my app.
most of them suggest me UIPickerView for the drop down box.
But my requirement is i need to place two drop down boxes in my app.
MY code for UIPicker view is
- (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:开发者_C百科(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];
}
this works for one button click, I need to open another array values for the another button click.
how can i done this.
PLs help me.
Thank U in advance.
I think you need tag assignment for all picker view. Assign two different tag for both picker view.
Now simply get tag from thePickerView argument and take respective action inside delegate. i.e - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { switch(thePickerView.tag){ case 101: return [arrayImage count]; case 102: return [arrayColors count]; } }
精彩评论