我正在尝试将UIPickerView放在我的应用程序导航栏中的Popover视图中。当我点击将打开popover的按钮时,我收到以下错误:
-[PopoverView pickerView:numberOfRowsInComponent:]: unrecognized selector sent to instance 0x75577f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PopoverView pickerView:numberOfRowsInComponent:]: unrecognized selector sent to instance 0x75577f0'
这就是我的.h文件中的内容:
#import <UIKit/UIKit.h>
@interface PopoverView : UIViewController {
IBOutlet UIPickerView *pickerView;
NSMutableArray *pickerArray;
}
@end
这就是我的.m文件:
#import "PopoverView.h"
@interface PopoverView ()
@end
@implementation PopoverView
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// initalizes and allocates the array that holds the values for the picker
pickerArray = [[NSMutableArray alloc] init];
//adds the values to the array
[pickerArray addObject:@"Blue"];
[pickerArray addObject:@"Green"];
[pickerArray addObject:@"Orange"];
[pickerArray addObject:@"Pink"];
[pickerArray addObject:@"Purple"];
[pickerArray addObject:@"Red"];
[pickerView selectRow:0 inComponent:0 animated:NO];
}
- (NSInteger)numberOfComponentsInPickerView:(NSInteger)component {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)picker numberofRowsInComponent:(NSInteger)component{
return [pickerArray count];
}
- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [pickerArray objectAtIndex:row];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
这是因为我试图在我的PopoverView类中创建选择器和数组而不是包含按钮操作代码的类吗?
答案 0 :(得分:2)
你的
中有拼写错误-(NSInteger)pickerView:(UIPickerView *)picker numberofRowsInComponent:(NSInteger)componen
HERE ---^
方法。它应该是numberOfRowsInComponent
,大写字母为“O”。