1

I'm trying to display a UINavigationController inside a UIPopoverController, but for some reason I can't set the title.

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:searchView];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

I tried changing it in the - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Change the title
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:20.0];
    label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.text = @"Print / Email";
    [label sizeToFit];
    self.navigationItem.titleView = label;
}
return self;
}

I also tried setting it in the - (void)viewDidLoad

- (void)viewDidLoad
{
[super viewDidLoad];

self.contentSizeForViewInPopover = CGSizeMake(320.0, 250.0f);

self.navigationItem.title = @"Print / Email";
self.title = @"Print / Email";
}

But in no cases the title is working, am I still doing something wrong?

woutr_be
  • 9,532
  • 24
  • 79
  • 129
  • try removing the titleview label code from - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil. – Manish Agrawal Aug 21 '12 at 06:30

3 Answers3

6

EDIT Add your SearchViewController controller in UINavigationController ad that in UIPopoverController like this:

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:searchView];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Now in SearchViewController's viewDidLoad method:

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.title = @"Print / Email";
}

Refer setting-the-title-of-a-uipopovercontroller

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
1

Try with this way to show popover controller

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];
UINavigationController *navCont=[[UINavigationController alloc] initWithRootViewController:searchView];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navCont];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Nikunj
  • 987
  • 11
  • 25
1

You can try this:

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];

UINavigationController *_nav = [[[UINavigationController alloc] initWithRoot.....:searchView] autorelease];

then put _nav into the popover.

each UIViewController has its own tabbar and navigation but you should init them.then you can use them rightly.

nmc
  • 8,724
  • 5
  • 36
  • 68
Swu_Log
  • 31
  • 4