我需要在我的应用中显示下拉框。
他们中的大多数人都建议我使用UIPickerView作为下拉框。
但我的要求是我需要在我的应用程序中放置两个下拉框。
UIPicker视图的MY代码是
- (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];
}
这适用于单击一次按钮,我需要为另一个按钮单击打开另一个数组值。
我该怎么做呢。
PL帮助我。
提前感谢你。
答案 0 :(得分:1)
我认为您需要为所有选择器视图分配标记。 为两个选择器视图分配两个不同的标记。
现在只需从thePickerView参数中获取标记,并在委托中执行相应的操作。 即 - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { 开关(thePickerView.tag){ 案例101: return [arrayImage count]; 案例102: return [arrayColors count]; } }