开发者

adding navigation effect to view based application?

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 [se开发者_如何转开发lf.view addSubview:sView]; but i need navigation effect. Thanks in advance.


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 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜