Reputation: 1571
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];
[theView setPopover:aPopover];
[theView release];
[self.popoverController presentPopoverFromRect:CGRectMake(510,370,0,0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Upvotes: 7
Views: 4612
Reputation: 21
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)
Upvotes: 1
Reputation: 1853
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];
Upvotes: 4
Reputation: 45598
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.
Upvotes: 7
Reputation: 10621
Try to set the title of the contentViewController of your popOver:
theView.title = @"My Title";
or
theView.navigationItem.title = @"My Title";
Upvotes: 0