我有两个UIPickerViews从数组中提取数据虽然我似乎无法单独编程。这是我用于UIPickerViews的代码:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [treatments count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return[[treatments objectAtIndex:row]valueForKey:@"treatmentName"];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
_buttonText.text = [[treatments objectAtIndex:row]valueForKey:@"treatmentName"];
if (![_buttonText.text isEqual: @"Pick a Treatment Name"]) {
_buttonText.textColor = [UIColor blackColor];
}
}
-(NSInteger)nursePicker:(UIPickerView *)nursePicker numberOfRowsInComponent:(NSInteger)component {
return [nurses count];
}
- (NSString *)nursePicker:(UIPickerView *)nursePicker titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return[[nurses objectAtIndex:row]valueForKey:@"nurseName"];
}
当我运行代码时,选择器显示相同的数据
提前致谢
答案 0 :(得分:0)
您应该使用BOOL来检查数据。创建一个名为treatment的BOOL,当第一个选择器可用时,将BOOL设置为YES,当第二个选择器可用时,将BOOL设置为NO。然后检查你的方法,看看哪个选择器是他们的,并放入数据。
@interface NotesViewController ()
{
BOOL treatment;
}
- (void)firstPickerComesUP
{
treatment = YES;
}
- (void)secondPickerComesUP
{
treatment = NO;
}