我有一个UIPickerView
我正在尝试为其设置数据源;设置好后datasource
,我将其放入要显示的模式弹出框中。这是代码 - manicuristArray 定义为NSArray
, pvManicurist 是UIPickerView
,所有代表UIPickerView
都已正确设置,根据我在 SO 上找到的示例):
-(void) showModalManicurist:(int)tag {
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 216)];
popoverView.backgroundColor = [UIColor redColor];
popoverContent.contentSizeForViewInPopover = CGSizeMake(300.0, 216.0);
// define the UIPickerView
pvManicurist.frame = CGRectMake(0, 0, 300, 216);
// fill the names from the d/b into manicuristArray
PreferenceData *pv = [PreferenceData MR_findFirst]; // (everything is in one record)
NSLog(@"pv.aStaffPos1: %@", pv.aStaffPos1);
if(pv) { // fill the UIPickerView
self.manicuristArray = [[NSArray alloc] initWithObjects: pv.aStaffPos1, pv.aStaffPos2, pv.aStaffPos3, pv.aStaffPos4, pv.aStaffPos5,
pv.aStaffPos6, nil];
NSLog(@"\nmanicuristArray.count: %d",manicuristArray.count);
pvManicurist.dataSource = self.manicuristArray; [pvManicurist reloadAllComponents];
}
// add it to the popover
[popoverView addSubview:pvManicurist];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate = (id)self;
[popoverController setPopoverContentSize:CGSizeMake(300, 216) animated:NO];
// show it below the staff name textbox
[popoverController presentPopoverFromRect:boStaff.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
问题是我收到了这个构建警告:
构建错误:从不兼容的类型“NSArray *”分配给“id”
我认为这导致UIPicker
视图不被放入UIPopover
. 我还有其他几个弹出窗口,都UIDatePickers
在其中,而且它们工作正常。我查看了 SO 和 Google 并没有发现任何可以回答这个特定问题的东西,即:为什么这不起作用?以及如何修复构建错误?
更新:这是 UIPickerView 的委托方法:
//-- sets number of columns
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pvManicurist {
return 1; // One column
}
//-- sets count of manicuristArray
-(NSInteger)pickerView:(UIPickerView *)pvManicurist numberOfRowsInComponent:(NSInteger)component {
return manicuristArray.count; //set number of rows
}
//-- sets the component with the values of the manicuristArray
-(NSString *)pickerView:(UIPickerView *)pvManicurist titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [manicuristArray objectAtIndex:row]; //set item per row
}
这是 .h 文件中的界面:
@interface AppointmentsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UINavigationControllerDelegate, UIActionSheetDelegate, UITextFieldDelegate,UIPickerViewDelegate, UIPickerViewDataSource > {