views:

43

answers:

3

Hi

I have created View based application, here i need to navigate between views when button pressed. so in first view controller i have created action for button pressed.

-(IBAction)loadSecondView:(id)sender
{
    SecondView *sView = [[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
    [self.navigationController pushViewController:sView animated:YES];
    [sView release];
}

this code is not working, anything i am missing,

i can do this by [self.view addSubview:sView]; but i need navigation effect. Thanks in advanced.

+1  A: 

You can't just hook a UIView instance to a navigation controller, that's not how they work.

Take a look at the "Navigation-based Application" template in Xcode, to learn how navigation controllers work.

You can use view controllers while hiding the navigation bar:

[[self navigationController] setNavigationBarHidden:YES animated:NO];

You can then map UIButton instances to selectors that push or pop view controllers, while keeping the navigation bar hidden.

These button instances are subviews of the view controller's view property.

Hiding the navigation bar can help provide the illusion that you are not using a navigation controller, while giving you all the functionality of the navigation controller.

Alex Reynolds
Thanks Ive been looking for confirmation of this technique for a while.
daidai
A: 

Alex is right, if you create just a "View Based Application" project, no UINavigationController was created so when you push something on it nothing happen, that's normal.

You have to create a UINavigationController and make you main view its rootViewController, then you can push on it a new viewController.

Greensource
A: 

I have got a solution for this,

In View based application the appdelegate file creates object for, view controller and added that view to main window, to do our task, delete the controller in mainwindow.xib and add a UINavigation controller,and create a object to it, and connect outlet to it,and then add this navigation controller view as a sub view,

its work fine.

mac