views:

321

answers:

2

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];
A: 

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

theView.title = @"My Title";

or

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

AlexVogel
+1  A: 

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.

Mike Weller
It doesn't look the same if you add the nav bar from IB.
Yazzmi
Ah of course... yeah the popover modifies the nav controller to look black and translucent. So you should wrap the view controller in a navigation controller.
Mike Weller
could you show me how to do that using the code adobe? thx!
Yazzmi
See my updated answer.
Mike Weller
add view to nav controller then add nav controller to popover controller then set title for nav controller?
Yazzmi