Objective c 动态UIPickerView更新
我有两个UIPickerView的问题 第一个名为pickerParent的采摘者选择一种食物。 然后,第二个名为pickerChild的采摘者显示了这些类型食物的列表 问题是,如果pickerChild尝试选择其中一个项目,pickerChild将更新自身以匹配pickerParent列表中的相应项目。(例如:如果您在pickerParent上选择肉类,pickerChild将显示“姜牛肉、柠檬鸡、盐椒排骨和糖醋猪肉”。如果您在pickerChild列表中选择糖醋猪肉,作为列表中的第四项,它将获得蔬菜属性,并且仅显示“什锦蔬菜”) 有人能帮我让pickerChild不更新自己吗 我的代码如下Objective c 动态UIPickerView更新,objective-c,xcode,dynamic,uipickerview,Objective C,Xcode,Dynamic,Uipickerview,我有两个UIPickerView的问题 第一个名为pickerParent的采摘者选择一种食物。 然后,第二个名为pickerChild的采摘者显示了这些类型食物的列表 问题是,如果pickerChild尝试选择其中一个项目,pickerChild将更新自身以匹配pickerParent列表中的相应项目。(例如:如果您在pickerParent上选择肉类,pickerChild将显示“姜牛肉、柠檬鸡、盐椒排骨和糖醋猪肉”。如果您在pickerChild列表中选择糖醋猪肉,作为列表中的第四项,它将
#import "MasterViewController.h"
#import "DetailViewController.h"
@interface MainPage () {
NSMutableArray *_objects;
}
@end
@implementation MainPage
@synthesize pickerChild;
@synthesize pickerParent;
@synthesize image_view;
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return ( pickerView == pickerParent ? 1 : 1 );
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
NSArray *values = ( pickerView == pickerParent ? topics : items );
return [values count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
NSArray *values = ( pickerView == pickerParent ? topics : items );
return [values objectAtIndex: row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if ([[topics objectAtIndex:row] isEqual:@"Noodles"]) {
items = noodle;
} else if ([[topics objectAtIndex:row] isEqual:@"Rice"])
{
items = rice;
} else if ([[topics objectAtIndex:row] isEqual:@"Meat"])
{
items = meat;
} else if ([[topics objectAtIndex:row] isEqual:@"Vegetables"])
{
items = vegatable;
} else if ([[topics objectAtIndex:row] isEqual:@"Favorites"])
{
items = favorite;
}
[pickerChild reloadAllComponents];
}
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
topics = [[NSMutableArray alloc] init];
[topics addObject:@"Noodles"];
[topics addObject:@"Rice"];
[topics addObject:@"Meat"];
[topics addObject:@"Vegetables"];
[topics addObject:@"Favorites"];
noodle = [[NSMutableArray alloc] init];
[noodle addObject:@"Fried Noodles"];
[noodle addObject:@"Shanghai Noodles"];
meat = [[NSMutableArray alloc] init];
[meat addObject:@"Ginger Beef"];
[meat addObject:@"Lemon Chicken"];
[meat addObject:@"Salt & Pepper Ribs"];
[meat addObject:@"Sweet & Sour Pork"];
vegatable = [[NSMutableArray alloc] init];
[vegatable addObject:@"Assorted Vegetables"];
rice = [[NSMutableArray alloc] init];
[rice addObject:@"Fried Rice"];
items = noodle;
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
@end
您的
didSelectRow..
delegate方法不区分这两个选择器,因此您的子选择器将重新加载您更改的任何选择器。仅当父选择器中的选择已更改时,才需要重新加载子选择器
因此,将您当前拥有的代码包装到:
if (pickerView == parentPicker)
你应该没事的