esreli
esreli

Reputation: 5071

ABPersonViewController in modally presented UINavigationController

The practical solution of my problem is to present a UINavigationController modally that has a UINavigationBar at the top containing a title and a left bar button with the title @"Done" that will dismiss the modal UINavigationController.

For whatever reason, I cannot figure out how to successfully implement this. I understand this is not the traditional use for a UINavigationController and i'm sure it's a simple solution but I cannot figure it out.

What I have tried is this:

ABPersonViewController *personVC = [ABPersonViewController personControllerWithCard:card];

personVC.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(ClosePeoplePicker)];

testerVCF = [[UINavigationController alloc]  initWithRootViewController:personVC];

[self presentViewController:testerVCF animated:TRUE completion:^
{
    NSLog(@"Completed");
}];

When I execute this code, a UINavigationController is presented but with no title and with no Done button.

Might you have a suggestion? I just don't think i'm thinking in line with how a UINavigationContoller operates.

Thanks in advance.

Upvotes: 2

Views: 397

Answers (2)

altyus
altyus

Reputation: 606

The problem is you're setting the navigation controller's barButton items, and title in the wrong place. What you should do instead is

  • configure the barButton items in the personVC's viewWillAppear method (You can access the navigationController in any view controller by accessing UIViewController's navigationController property) ie. [self.navigationController setBarButtonItem:myBarButtonItem];
  • implement the dismissPersonVC method inside of the PersonVC Class

Upvotes: 2

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19862

If your main view controller is UIViewController than you should read that:

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html#//apple_ref/doc/uid/TP40007457-CH18-SW6

Especially that part:

- (void) displayContentController: (UIViewController*) content
{
   [self addChildViewController:content];                 // 1
   content.view.frame = [self frameForContentController]; // 2
   [self.view addSubview:self.currentClientView];
   [content didMoveToParentViewController:self];          // 3
 }

- (void) hideContentController: (UIViewController*) content
{
   [content willMoveToParentViewController:nil];  // 1
   [content.view removeFromSuperview];            // 2
   [content removeFromParentViewController];      // 3
}

Upvotes: 0

Related Questions