简体   繁体   English

如何使用Interface Builder正确控制UINavigationControllers?

[英]How do you use Interface Builder to control UINavigationControllers properly?

I have been in the process of learning to build iPhone applications for the last two weeks. 最近两个星期,我一直在学习构建iPhone应用程序的过程。 I've gotten through a fair amount of content, and now I'm trying to create a modal pop up with presentModalView. 我已经了解了很多内容,现在我正在尝试使用presentModalView创建一个模式弹出窗口。

I can can successfully create and slide up a view, but I notice that modal views don't provide you with a default navigation bar at the top of the window, which makes sense for flexibility I guess. 我可以成功创建并向上滑动视图,但是我注意到模式视图在窗口顶部没有为您提供默认的导航栏,我想这对于灵活性很有用。 Most modal views I've seen have a "Cancel" and a "Done" or "Save" button as navigationItems on what looks to be a UINavigationController. 我见过的大多数模式视图在看起来像UINavigationController的导航项目上都有一个“取消”和“完成”或“保存”按钮。 My thought then was just to instantiate a navigation controller and push the single view onto the view controller stack, and presentModalView:navController.view ... 然后我的想法只是实例化导航控制器,并将单个视图推到视图控制器堆栈上,然后presentModalView:navController.view ...

Because the view is relatively complex, I was trying to lay out both the UINavigationController, with the bar buttons, and the view I was hoping to push onto the stack in a single xib -- no matter what I try, I can't seem to get the linkages correct. 因为视图相对复杂,所以我试图用条形图按钮布置UINavigationController和希望通过单个xib推入堆栈的视图—不管我尝试什么,我似乎都无法使链接正确无误。 Can you even do this? 你能做到吗? Or should I create a separate class/xib for the view I'm going to be pushing onto the navigation controller? 还是应该为要推送到导航控制器上的视图创建单独的类/ xib? Seems like a lot of classes and files for one screen, so my feeling is I must be missing something. 似乎在一个屏幕上有很多类和文件,所以我的感觉是我一定缺少一些东西。

At this point, I could have done it programmatically about an hour and a half ago... however, this is a real nag, since IB seems GREAT for some things. 在这一点上,我本可以在一个半小时左右之前以编程方式完成它的工作……但是,这真是令人头疼,因为IB在某些方面似乎很棒。 Anyone have an experience with a situation like this? 任何人都经历过这种情况吗?

Thanks, Josh 谢谢,乔希

If you're not going to use this new XIB for navigation, there's no point in making a navigation controller. 如果您不打算使用这个新的XIB进行导航,那么制作导航控制器毫无意义。

In interface builder, simply drag a UINavigationBar to the top of your view, and add a "Done" Button. 在界面构建器中,只需将UINavigationBar拖动到视图顶部,然后添加“完成”按钮。 Now, add an IBAction to the done button to dismiss the view controller. 现在,将IBAction添加到完成按钮以关闭视图控制器。 Your ViewController code for the dismiss IBAction should look something like this: 关闭IBAction的ViewController代码应如下所示:

-(IBAction)dismiss {
    //Any logic before dismissing the modal view
    [super dismissModalViewControllerAnimated:YES];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM