ios 在具有 .xib 文件的项目中使用故事板 - iPhone
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9701873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use storyboards in a project which has .xib files- iPhone
提问by George Sachpatzidis
I want to use generally the old .xib files in my iPhone application. But when it comes to tableViewController storyboard is a lot more convenient in order to make custom cells etc. Is it possible to make a .xib based application and in the middle of it, to use a storyboard for a UITableViewController and its DetailedViewController only?
我想在我的 iPhone 应用程序中使用旧的 .xib 文件。但是当谈到 tableViewController 故事板时,为了制作自定义单元格等要方便得多。 是否可以制作一个基于 .xib 的应用程序,并在它中间,仅将故事板用于 UITableViewController 及其DetailedViewController?
回答by Jon Hess
You can use a storyboard for any part of a program. Storyboards are not an all or nothing concept. You can have just one view controller in a storyboard, or a small network that just represents a subsection of your app.
您可以将故事板用于程序的任何部分。故事板不是一个全有或全无的概念。您可以在故事板只是一个视图控制器,或者只是代表你的应用程序的第一个小型网络。
To use just one view controller from a storyboard:
要仅使用故事板中的一个视图控制器:
- Add a new storyboard to your existing project.
- Add a single view controller to the storyboard.
- Assign an identifier to the view controller in the inspector.
- Use the UIStoryboard class to load the storyboard resource
- Use -[UIStoryboard instantiateViewControllerWithIdentifier:] to create a new instance of that view controller.
- Install the view controller some place in your app by doing something like pushing it on to a navigation controller, or run it modally.
- 向现有项目添加新的故事板。
- 将单个视图控制器添加到故事板。
- 在检查器中为视图控制器分配一个标识符。
- 使用 UIStoryboard 类加载故事板资源
- 使用 -[UIStoryboard instantiateViewControllerWithIdentifier:] 创建该视图控制器的新实例。
- 通过执行诸如将视图控制器推送到导航控制器之类的操作,将视图控制器安装在您的应用程序中的某个位置,或以模态方式运行它。
回答by LJ Wilson
Both can work fine together (Storyboards and Nib files). In the TVC that is part of your storyboard, just instantiate the destination VC in code and use the usual initWithNibName method to load the nib file.
两者都可以很好地协同工作(故事板和 Nib 文件)。在属于故事板的 TVC 中,只需在代码中实例化目标 VC 并使用通常的 initWithNibName 方法加载 nib 文件。
回答by atrljoe
You can add a storyboard to any project, but the point of storyboards is to centralize your XIB files into one location rather than having 10 XIB files you can have 1 .storyboard
file that contains 10 scenes representing your views. This shows your connections to other scenes, and you can manage all the seques and transitions of each scene. So is it possible, yes you could add a storyboard to your project, but I would recommend you design you entire application in a storyboard if you want to use them.
您可以向任何项目添加故事板,但故事板的重点是将您的 XIB 文件集中到一个位置,而不是拥有 10 个 XIB 文件,您可以拥有 1 个.storyboard
包含 10 个代表您的视图的场景的文件。这显示了您与其他场景的联系,您可以管理每个场景的所有序列和过渡。那么有可能吗,是的,您可以将故事板添加到您的项目中,但是如果您想使用它们,我建议您在故事板中设计整个应用程序。