Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add navigation bar programmatically to a tableviewController (segue push or modal )

I'm trying to programmatically add a navigationBar to a tableViewController :

Example screenshot:

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.

like image 819
Damien Locque Avatar asked May 21 '12 14:05

Damien Locque


1 Answers

naviBarObj's frame ypoint is -260, maybe this is making nothing appear.

like image 177
Reilost Avatar answered Nov 01 '22 07:11

Reilost