Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PresentModalViewController not showing navigation bar on next view

Hello I am using One tab bar button on toolbar , this button will show next view with table view ,Here is my code

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

my problem is that when I click this tab bar button it will showing next view with tableview but not navigation bar. because of this i am unable to perform delete operation in tableView.

How to solve the issue?

like image 636
iProgrammer Avatar asked May 19 '11 09:05

iProgrammer


3 Answers

That is because you are using Modal to bring the new view controller.

Modally added/presented view controller will not be added to the navigation controller stack

like image 86
Pramodh Avatar answered Nov 15 '22 04:11

Pramodh


If you dont find the UINavigationBar on the next class means , it does not have a navigation controller, so before pushing it add a UINavigationController to your next view.

Try like this:

NextViewController *nextViewController=[[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:nextViewController];
[self.navigationController presentModalViewController:navBar animated:YES];
[navBar release];
[nextViewController release];

see this stackoverflow question for edit option.

You can simply add a button to navigation bar with ease

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(editTable)] autorelease];

-(void)editTable{
[tableView setEditing: YES animated: YES];
}

All the best.

like image 39
Warrior Avatar answered Nov 15 '22 03:11

Warrior


This code is called on button click event in classA VC:

ClassBVC* bVc = [[ClassBVC alloc] initWithNibName:@"ClassBVC" bundle:nil];
     UINavigationController* tempNavCon = [[UINavigationController alloc]    initWithRootViewController:bVc];
    [self presentModalViewController:tempNavCon animated:YES];
    [tempNavCon release];
    [bVc release];
    bVc = nil

;

and in class BVC in view did load you make an UIbarbutton item e.g:

UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked:)];
    [barButton setTitle:@"Back"];
    [self.navigationItem setLeftBarButtonItem:barButton];
    [barButton release];

And in buttonClickedMethod simply dismiss the the model controller as:

-(void)backButtonClicked:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}
like image 29
Himanshu Agnihotri Avatar answered Nov 15 '22 03:11

Himanshu Agnihotri