[英]getting confusion with how to open Two array values for Two Button click events in UIPicker view
我需要在我的应用程序中显示下拉框。
他们中的大多数人建议我在下拉框中输入UIPickerView。
但是我的要求是我需要在应用程序中放置两个下拉框。
我的UIPicker视图代码是
- (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];
}
这适用于一个按钮单击,我需要为另一个按钮单击打开另一个数组值。
我该怎么做。
请帮助我。
预先感谢您。
我认为您需要为所有选择器视图分配标签。 为两个选择器视图分配两个不同的标签。
现在,只需从thePickerView参数获取标签,并在委托中执行相应的操作。 即-(NSInteger)pickerView:(UIPickerView *)PickerView numberOfRowsInComponent:(NSInteger)component {switch(thePickerView.tag){案例101:返回[arrayImage count]; 案例102:返回[arrayColors count]; }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.