I'm trying to programmatically add a navigationBar to a tableViewController :
When I come from a PUSH Segue the builder adds a navigation bar with navigation items, like I want.
But the problem is that when i come form a MODAL Segue I try to add a bar with code like this:
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, -260, 320, 44)];
[self.view addSubview:naviBarObj];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelButtonPressed)];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonPressed)];
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
navigItem.rightBarButtonItem = doneItem;
navigItem.leftBarButtonItem = cancelItem;
naviBarObj.items = [NSArray arrayWithObjects: navigItem,nil];
....
- (void) cancelButtonPressed { }
- (void) doneButtonPressed { }
But nothing appears... No top bar.
naviBarObj's frame ypoint is -260, maybe this is making nothing appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With