I am having trouble with two UIPickerViews.
The first picker named pickerParent selects a type of food. The second picker named pickerChild then shows a list of those types of food.
The problem is if pickerChild tries to select one of those items, pickerChild then updates itself to match the corresponding item on the pickerParent's list. (ex: if you select meat on pickerParent, pickerChild displays "Ginger Beef, Lemon Chicken, Salt & Pepper Ribs, and Sweet & Sour Pork". If you then select Sweet & Sour Pork on the pickerChild List, being the fourth item on the list, it will then gain the attributes of Vegetables and only display "Assorted Vegetables")
Can someone help me so pickerChild doen't update itself?
my code is below.
#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