I implemented a simple UIPickerView in my app and I keep getting warnings that I can’t explain about incomplete implementation and “method in protocol not completed”. I went through a bunch of examples and could not figure out what am I missing.
Here is my code:
.h
@interface ViewTestViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UIPageViewControllerDataSource, UIPageViewControllerDataSource> {
UIPickerView *pickerView;
NSMutableArray *pickerList;
....
}
@property (nonatomic, retain) IBOutlet UIPickerView *pickerView;
@property (nonatomic, retain) NSMutableArray *pickerList;
@end
.m
- (void)viewDidLoad
{
[super viewDidLoad];
…
//PICKER AREA
pickerList = [[NSMutableArray alloc] init];
[pickerList addObject:@"aaa"];
[pickerList addObject:@"bbb"];
CGRect pickerFrame = CGRectMake(0, 200, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
}
-(IBAction)showPicker:(id)sender {
[self.view addSubview:pickerView];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
return [pickerList count];
}
-(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [pickerList objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"Selected item: %@ index of selected item: %i", [pickerList objectAtIndex:row], row);
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 200;
}
You need to conform to the
UIPickerViewDelegateandUIPickerViewDataSourcein your .h like you do for UITableViewDelegate, UITableViewDataSource etc (you’re currently not)Also, make sure you are setting
selfas the picker view delegate and data source when you create it: