我对 Xcode 和任何与编码有关的事情都是全新的,但我正在努力,直到现在似乎一切都很好。我想做的事...
我有一个UIPickerView
由数组填充的 2 个组件。这很好,很可爱,但我希望更进一步。
在左侧组件上,我希望有一个具有永远不会改变的常量值的列表。在第二个组件中,我希望有一个在第一个组件中单击的任何选择的子列表。
例如:-
BOY : Matt
Tom
Pete
GIRL : Jess
Nina
Sarah
我想我可以使用一个if
语句来实现这些更改,但不知道语言......一个人只能进行这么多的试验和错误!
干杯
@interface TripsViewController ()
@end
@implementation TripsViewController
@synthesize ActivitysLabel;
@synthesize TripsLabel;
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == ACTIVITY)
return [ArrayActivity count];
if (component == TRIPS)
return [ArrayTrips count];
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == ACTIVITY)
return [ArrayActivity objectAtIndex:row];
if (component == TRIPS)
return [ArrayTrips objectAtIndex:row];
return 0;
}
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
ActivitysLabel.text = [ArrayActivity objectAtIndex:[pickerView selectedRowInComponent:0]];
TripsLabel.text = [ArrayTrips objectAtIndex:[pickerView selectedRowInComponent:1]];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
ArrayActivity = [[NSMutableArray alloc] init];
[ArrayActivity addObject:@"Abseiling"];
[ArrayActivity addObject:@"Canyoning"];
[ArrayActivity addObject:@"Rock Climbing"];
[ArrayActivity addObject:@"Bush Walking"];
[ArrayActivity addObject:@"Mountain Biking"];
[ArrayActivity addObject:@"4wd Tours"];
// My attempts at trying to solve this problem
if (ArrayActivity containsObject:NSString @"Canyoning") {
ArrayTrips = [[NSMutableArray alloc] init];
[ArrayTrips addObject:@"Empress Canyon"];
[ArrayTrips addObject:@"Sheep Dip"];
[ArrayTrips addObject:@"butterbox"];
}