繁体   English   中英

UIPickerView无法解释的警告

[英]unexplained warnings with UIPickerView

我在应用程序中实现了一个简单的UIPickerView,并且不断收到警告,提示我无法解释未完成的实现和“协议中的方法未完成”。 我列举了很多例子,但无法弄清我想念的是什么。

这是我的代码:

。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;
}

您需要遵循.h中的UIPickerViewDelegateUIPickerViewDataSource ,就像您对UITableViewDelegate,UITableViewDataSource等所做的一样(当前不是)

@interface ViewTestViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UITableViewDelegate, UITableViewDataSource, UIPageViewControllerDataSource, UIPageViewControllerDataSource> {

另外,请确保在创建self将其设置为选择器视图委托和数据源:

//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; 
pickerView.dataSource = self;
pickerView.delegate = self;

在您的.h文件中,您声明自己符合以下协议:

<UITableViewDelegate, UITableViewDataSource, UIPageViewControllerDataSource, UIPageViewControllerDataSource>

这些协议中的每一个都涉及您必须实现的某些方法(有关详细信息,请参见每个协议的文档)。 如果未实现所有必需的方法,则会收到此警告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM