我在UIPopoverController中使用UIPickerView时遇到了一个奇怪的问题。我通过以下代码编写此任务:
UIPickerView *select = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
select.delegate = self;
select.dataSource = self;
UIViewController *sortViewController = [[UIViewController alloc] init];
sortViewController.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
sortViewController.view = select;
sortViewController.preferredContentSize = CGSizeMake(320, 216);
self.provincePickerPopover = [[UIPopoverController alloc] initWithContentViewController:sortViewController];
self.provincePickerPopover.popoverContentSize = CGSizeMake(320, 216);
self.provincePickerPopover.delegate = self;
[self.provincePickerPopover presentPopoverFromRect:self.provinceField.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
问题是当弹出窗口启动时,发生以下错误:
[UIPickerView setFrame:]: invalid height value 229.0 pinned to 216.0
在我的代码中很明显,我从未使用过229作为UIPickerView的高度。我怎么能解决这个问题?
由于
答案 0 :(得分:0)
将选择器视图添加为UIViewController视图的子视图。这将摆脱错误。所以,像这样:
...
UIViewController *sortViewController = [[UIViewController alloc] init];
sortViewController.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
[sortViewController.view addSubview:select]
sortViewController.preferredContentSize = CGSizeMake(320, 216);
...