简体   繁体   English

如何为UIPopOverController的导航栏设置标题?

[英]How to set title to UIPopOverController's Navigation Bar?

I am working on IPad application.Here it consists of PopOver.There I need to show camera and capture the image.For that I am using AVFoundation Framework,where default navigation bar is not appeared.So I followed the below procedure 我正在使用iPad应用程序,它由PopOver组成。我需要显示相机并捕获图像。为此,我正在使用AVFoundation Framework,其中没有出现默认导航栏。因此,我按照以下步骤进行操作

cameraVC = [[CameraViewController alloc] initWithNibName:@"CameraViewController" bundle:nil ];
cameraVC.navigationItem.title = @"Take Photo";

UINavigationController *naviCon = [[UINavigationController alloc]initWithRootViewController:cameraVC];

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:naviCon];
 self.popoverController = popover;
 self.popoverController.delegate = self;
 self.popover.popoverContentSize = CGSizeMake(450, 350);

[self.popoverController presentPopoverFromRect:CGRectMake(295, 40, 0, 0) inView:appDelegate.splitview.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Please guide me where I was wrong if you have worked on it.Thanks in advance 如果您曾经尝试过,请告诉我哪里错了。

在此处输入图片说明

Modify code as below and check 如下修改代码并检查

cameraVC = [[CameraViewController alloc] init];

UINavigationController *naviCon = [[UINavigationController alloc]initWithRootViewController:cameraVC];

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:naviCon];
 [self.presentPopOverController presentPopoverFromBarButtonItem:self.yourBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

and then in viewDidLoad method of CameraViewController write following code 然后在CameraViewController viewDidLoad方法中编写以下代码

self.navigationItem.title = @"your title";

If the Navigation bar does not appear, add a UIToolBar in your cameraViewController to do the functionality you want. 如果没有出现导航栏,请在cameraViewController中添加UIToolBar以执行所需的功能。

I do something like this in my project and I get the navigationBar in the popOVer presented. 我在项目中执行了类似的操作,并在popOVer中获得了NavigationBar。

        PageSelectorViewController *pageSelector=[[PageSelectorViewController  alloc]initWithStyle:UITableViewStylePlain] ;
        UINavigationController *navControl=[[UINavigationController alloc]initWithRootViewController:pageSelector];

        self.selectedPagesPopOver=[[UIPopoverController alloc]initWithContentViewController:navControl];
        [self.selectedPagesPopOver presentPopoverFromBarButtonItem:showPages permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

I guess presenting the popOver from a custom rect is the problem, try to present from a BarButton and try. 我想从自定义矩形中呈现popOver是问题,请尝试从BarButton呈现,然后尝试。

This could help you… 这可以帮助您...

MyController* controller = [[MyController alloc] initWithNibName:@"MyController" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:controller];

controller.title = @"My Title"; //or you can put this line in MyController class viewDidLoad method as self.title = @"My Title";

controller.contentSizeForViewInPopover = CGSizeMake(320.0, 480.0);

_myPopover = [[UIPopoverController alloc] initWithContentViewController:navController];

[_myPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

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

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