views:

263

answers:

2

hi..

I have a problem, In my app there is requirement that..I have 6 buttons in a nib, when i press any button a new nib will be loaded into the window according to the button pressed. problem is after loading the new nib If I want to come back to the previous nib (which is having all the buttons) how to add navigation controller?

what i am doing now is while loading the new nib when i pressed the button

objNewViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[self.navigationController pushViewController:objNewViewController animated:YES];

but by this way im not able to load the nib, its not performing any operation?

can any one solve my problem?

A: 

There is a template in Xcode for a navigation based app. It does everything you describe. Well, very close at least, only the AnotherViewController in -tableView:didSelectRowAtIndexPath: is commented out.

Johan Kool
thank you for the reply johan..but the thing is the nib which is having these 5 to 6 buttons is not the first nib..i have 2 nibs before this..after that this buttons nib will come.here i cant take the navigation controller especially rite?that why i wanna add the navigation controller programatically atleast to come back till the nib which contains the buttons.
chaitanya
In that case, create the UINavigationController using its designated initializer (-init...) and add its view when you need it. You can the push other viewcontrollers on its stack after you've created them with -initWithNib...
Johan Kool
+1  A: 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil]];

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

And in NewViewController: USe this to dismiss and get back to previous view.

[[self navigationController] dismissModalViewControllerAnimated:YES];
Manjunath
when I do this it is loading my newViewController's nib, but the problem is it doesnt have any back button to come back.how to solve this?
chaitanya
you can add leftBarButton to navigation item. Add cancel button and in its action method, dismiss the model.
Manjunath