向基于视图的应用程序添加导航效果?

发布于 2024-09-07 23:20:25 字数 446 浏览 5 评论 0原文

我创建了基于视图的应用程序,在这里我需要在按下按钮时在视图之间导航。 因此,在第一个视图控制器中,我为按下的按钮创建了操作。

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

这段代码不起作用,我缺少任何东西,

我可以通过 [self.view addSubview:sView]; 来做到这一点,但我需要导航效果。 提前致谢。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£噩梦荏苒 2024-09-14 23:20:25

您不能只是将 UIView 实例挂接到导航控制器,这不是它们的工作方式。

查看 Xcode 中的“基于导航的应用程序”模板,了解导航控制器的工作原理。

您可以在隐藏导航栏时使用视图控制器:

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

然后您可以将 UIButton 实例映射到推送或弹出视图控制器的选择器,同时保持导航栏隐藏。

这些按钮实例是视图控制器的 view 属性的子视图。

隐藏导航栏可以帮助您产生一种您没有使用导航控制器的错觉,同时为您提供导航控制器的所有功能。

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.

秋叶绚丽 2024-09-14 23:20:25

Alex 是对的,如果您只创建一个“基于视图的应用程序”项目,则不会创建 UINavigationController,因此当您向其推送某些内容时不会发生任何情况,这是正常的。

您必须创建一个 UINavigationController 并使您主视图其 rootViewController,然后您可以在其上推送一个新的 viewController。

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.

恍梦境° 2024-09-14 23:20:25

我对此有一个解决方案,

在基于视图的应用程序中,appdelegate 文件为视图控制器创建对象并将该视图添加到主窗口,为了完成我们的任务,删除 mainwindow.xib 中的控制器并添加一个 UINavigation 控制器,然后创建一个对象到它,并将插座连接到它,然后将此导航控制器视图添加为子视图,

其工作正常。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文