Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
NAUSHAD DARUWALLA
1,587 PointsHow to use pickerView
I am trying to use a picker view with three components in it and I have all the code in, but when i run it in the simulator the pickerView shows up blank. I've attached the pickerView to the .h file and then I have put in the delegate and dataSource methods (the following) -(void) viewWillAppear:(BOOL)animated { self.activityTypeArray = [[NSArray alloc] initWithObjects:@"Homework",@"Study", nil];
self.activityTypeActivityArray = [[NSArray alloc] initWithObjects:@"Quiz",@"Test", nil];
hierarchyTableViewController* classSourceArray = [[hierarchyTableViewController alloc] init];
self.classArray = [[NSArray alloc] initWithArray:classSourceArray.classHierarchyArray];
}
(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 3; }
-
(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == 0) {
return [self.activityTypeArray count];} else if (component == 1) { return [self.classArray count]; } else { return [self.activityTypeActivityArray count]; }
}
-
(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == 0) { return [self.activityTypeArray objectAtIndex:row]; } else if (component == 1) {
return [self.classArray objectAtIndex:row];} else { return [self.activityTypeActivityArray objectAtIndex:row]; }
}
Why is it not showing up in the simulator?