woutr_be
woutr_be

Reputation: 9722

UINavigationController in UIPopoverController: setting the title

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?

Upvotes: 1

Views: 3389

Answers (3)

Swu_Log
Swu_Log

Reputation: 31

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.

Upvotes: 1

Paresh Navadiya
Paresh Navadiya

Reputation: 38239

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

Upvotes: 6

Nikunj
Nikunj

Reputation: 987

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

Upvotes: 1

Related Questions