0

我需要显示一个简单的弹出视图,其中将显示带有完成按钮和选择器视图的导航栏。我正在以编程方式做所有事情,代码如下所示。

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。

4

1 回答 1

0

你正在以一种非常奇怪的方式经历这一切。这是你应该做的。与其制作自己的导航栏,不如使用UINavigationController.

1.) 创建一个navigationController,叫它navC
2.) 创建一个viewController,叫它vC
3.) 创建一个pickerView,叫它pV

4.) 使用属性 5.) 使用导航栏等设置 vC self.navigationItem.rightBarButtonItem
。) 将 pV 插入 vC -> [vC.view addSubview:pV]
6.) 将 vC 插入 navC ->navC.rootViewController = vC

7.) 将 navC 插入 popOver ->self.popvc = [[UIPopoverController alloc] initWithContentViewController:navC];

8.) 呈现视图。

利润。(PS 不要那样命名您的变量。将其命名为长且描述性的)

于 2013-05-23T19:17:35.420 回答