-1

我正在尝试将 UIPickerView 放在应用程序导航栏中的 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 类中创建选择器和数组而不是包含按钮操作代码的类吗?

4

1 回答 1

2

你有一个错字

-(NSInteger)pickerView:(UIPickerView *)picker numberofRowsInComponent:(NSInteger)componen
                                            HERE ---^

方法。它应该是numberOfRowsInComponent大写的“O”。

于 2013-06-05T15:37:58.393 回答