-1
我想在我的應用程序的導航欄中的一個Popover視圖裏面放一個UIPickerView。當我點擊按鈕,將打開酥料餅我得到以下錯誤:UIPickerView運行時錯誤無法識別的選擇發送到實例
-[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類,而不是包含該按鈕動作的代碼的類中選取器和陣列引起的?
哇,我不能相信我錯過了那個哈哈。這解決了問題!謝謝! – Rygarth
艾哈我試圖找到錯字,你已經更快;)。而Rygarth,你應該使'PopoverView'明確地實現'UIPopoverControllerDelegate':'@interface PopoverView:UIViewController'。 –
好的,我也會加上。謝謝GuillaumeA – Rygarth