I have been reading up on pickers and wanted to try and get a simple one working, but I do not know what I am doing wrong with my code.
I have assigned my pickers in my storyboard to the correct controllers. I then added the following to my header.
@interface CustomerView : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
{
IBOutlet UIPickerView * CompanyPicker;
IBOutlet UIPickerView * ClientPicker;
NSMutableArray *arrayCompanies;
NSMutableArray *arrayClients;
}
I then added some info to the arrays I created in my heading under didload:
arrayCompanies = [[NSMutableArray alloc] init];
[arrayCompanies addObject:@"Test Company 01"];
[arrayCompanies addObject:@"Test Company 02"];
[arrayCompanies addObject:@"Test Company 03"];
[arrayCompanies addObject:@"Test Company 04"];
[arrayCompanies addObject:@"Test Company 05"];
[arrayCompanies addObject:@"Test Company 06"];
[arrayCompanies addObject:@"Test Company 07"];
arrayClients = [[NSMutableArray alloc] init];
[arrayClients addObject:@"Test Client 01"];
[arrayClients addObject:@"Test Client 01"];
[arrayClients addObject:@"Test Client 01"];
[arrayClients addObject:@"Test Client 01"];
[arrayClients addObject:@"Test Client 01"];
[arrayClients addObject:@"Test Client 01"];
[arrayClients addObject:@"Test Client 01"];
After that I added the following in the implementation, but the info is not seeming to load into my arrays. Am I doing something wrong here?
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [arrayCompanies count];
return [arrayClients count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arrayCompanies objectAtIndex:row];
return [arrayClients objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"Selected Company: %@. Index of selected company: %i", [arrayCompanies objectAtIndex:row], row);
NSLog(@"Selected Client: %@. Index of selected client: %i", [arrayClients objectAtIndex:row], row);
}
use this technique: