我需要显示一个简单的弹出视图,其中将显示带有完成按钮和选择器视图的导航栏。我正在以编程方式做所有事情,代码如下所示。
CGRect displayFrame = CGRectMake(0, 0, 300.0f,500.0f);
//((CGFloat)[self.pocModelData.arrayOfDistricts count] + 25)
UIView *popoverView = [[UIView alloc] initWithFrame:displayFrame];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,popoverView.frame.size.width,20)];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"some title"];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissPopoverAnimated:)];
navItem.rightBarButtonItem = doneButton;
navBar.items = [NSArray arrayWithObjects:navItem, nil];
[popoverView addSubview:navBar];
CGRect displayFramePopOver = CGRectMake(0, 0, 600.0f,((CGFloat)[self.pocModelData.arrayOfDistricts count] - 25));
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:displayFramePopOver];
[popoverView addSubview:pickerView];
UIViewController *tvc = [[UIViewController alloc] init];
//tvc.view = popoverView;
[tvc setView:popoverView];
self.popvc = [[UIPopoverController alloc] initWithContentViewController:tvc];
self.popvc.delegate = self;
//[popvc setPopoverContentSize:CGSizeMake(400, 200)];
[self.popvc presentPopoverFromRect: anchor.frame inView: anchor.superview permittedArrowDirections: UIPopoverArrowDirectionAny animated: YES];
不幸的是,由于我没有 10 的声誉,我无法发布代码执行的结果,所以我将尝试解释显示的内容。显示了弹出框,但视图中有一个黑色矩形显示在似乎是深蓝色背景的地方。我正在寻找的是如何弄清楚如何正确设置视图和弹出框的大小,以便它显示正确的弹出框导航栏和 uipickerview。