开发者

Set the title of an UIPopOver View Programmatically

开发者 https://www.devze.com 2023-01-08 17:27 出处:网络
How do you set the title of an UIPopOver View programmatically? I found some sample code but wasn\'t able to set the title.

How do you set the title of an UIPopOver View programmatically?

I found some sample code but wasn't able to set the title.

myView *theView = [[myView alloc] initWithNibName:@"myView" 
                                       bundle:nil];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:theView];
[aPopover setDelegate:self];
[aPopover setPopoverContentSize:CGSizeMake(320, 320) animated:YES];

[th开发者_JS百科eView setPopover:aPopover];
[theView release];

[self.popoverController presentPopoverFromRect:CGRectMake(510,370,0,0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];


You need to wrap the view controller in a UINavigationCotnroller which will add a navigation bar with the appropriate title for the view controller. Something like this:

UINavigationController *container =
    [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];

Then just initialize your popover to use container instead and present it as usual.


yes, exactly. the whole thing could look like this:

InfoView *infoView = [[InfoView alloc] init];
UINavigationController *container = [[[UINavigationController alloc] initWithRootViewController:infoView] autorelease];
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:container];

infoView.title = @"My Title";

[pop setDelegate:self];
[pop setPopoverContentSize:CGSizeMake(320, 400)];
[pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[infoView release];


let popoverContent = (self.storyboard?.instantiateViewControllerWithIdentifier("Popover"))! as UIViewController
popoverContent.title = "Details"
let nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover = nav.popoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(100, 100)
popover!.delegate = self
popover!.sourceView = self.view
popover!.sourceRect = CGRectMake(100,100,0,0)

self.presentViewController(nav, animated: true, completion: nil)


Try to set the title of the contentViewController of your popOver:

theView.title = @"My Title";

or

theView.navigationItem.title = @"My Title";

0

精彩评论

暂无评论...
验证码 换一张
取 消