Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Trying to add Navigation Bar to Modal UITableViewController

I'm following the CoreDataRecipes app for modaly showing the add screen when I want to add a new item. However I cannot get the bar to display at the top so I can press 'Done' or 'Cancel'.

In the xib calling the modal controller I have the + button linked to modally sliding up the controller via IB.

I have the below in my modal controller

self.navigationItem.title = @"Add";

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(save)];
    self.navigationController.navigationBarHidden = NO;

In my viewDidLoad

The modal controller displays fine except there is no bar so I cannot leave that screen.

like image 223
Bot Avatar asked Dec 01 '22 00:12

Bot


1 Answers

You need to add it before the popover is actually presented.

Where you create the modal popover, you need to create it inside a UINavigationController first.

So, do the following.

 PopoverView *foo = [[PopoverView alloc] initWithNibName:@"PopoverView" bundle:nil];
 // Here you pass through properties if you need too.
 // ...
 UINavigationController *navC = [[UINavigationController alloc] initWithRootView:foo];
 [foo release];

 [self.navigationController presentModalViewController:navC animated:YES];

That will give the modal view the navigation bar which you're trying to edit.

like image 157
Sebastien Peek Avatar answered Jan 12 '23 00:01

Sebastien Peek