Reputation: 335
I'm still new to iOS coding but am trying to get my UIPicker to display the options I want, and then be able to take the option selected and do something with it. But rather than having the picker show my options it's just showing ? marks instead of my options.
Here's my GuardCompany.h
#import <UIKit/UIKit.h>
#define COLOUR 0
@interface GuardCompany : UIViewController
<UIPickerViewDataSource,UIPickerViewDelegate>{
IBOutlet UIPickerView *ColourAndShadePicker;
NSMutableArray *arrayColour;
}
@end
And here's my GuardCompany.m
#import "GuardCompany.h"
@interface GuardCompany ()
@end
@implementation GuardCompany
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component == COLOUR)
return [arrayColour count];
return 0;
}
- (NSString *)GuardCompany:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == COLOUR)
return [arrayColour objectAtIndex:row];
return 0;
}
#pragma mark - view lifecycle
-(void)viewDidLoad
{
[super viewDidLoad];
arrayColour = [[NSMutableArray alloc] init];
[arrayColour addObject:@"red"];
}
@end
Upvotes: 1
Views: 305
Reputation: 5361
At first glance this looks incorrect:
- (NSString *)GuardCompany:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
Change it to:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
Upvotes: 2