从情节提要中提取 nibs/xibs (iOS)
我创建了一个带有故事板的简单项目,现在意识到它们不支持 iOS 4.x,并且我希望使用这些设备的用户能够下载我的应用程序。该应用程序只是一个翻转视图控制器,并且相当简单,但如果有一种方法可以从故事板中提取 XIB,我更愿意这样做而不是重新创建它。
tl;dr:从 .storyboard 中获取 .xibs?
I have created a simple project with a storyboard, and now realize that they don't support iOS 4.x and that I would like users with these devices to be able to download my app. The app is just a flipside view controller, and is fairly simple but if there's a way to just extract the XIBs from the storyboard I'd much prefer to do that than recreate it.
tl;dr: getting .xibs out of a .storyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Xib 文件无法从情节提要中提取,但您可以通过将情节提要实例化为 UIStoryboard 对象并通过其标识符获取 UIViewController,从情节提要中实例化 UIViewController,以下是我的操作方法:
希望这会有所帮助。
Xib files cannot be extracted from the storyboard but you can instantiate UIViewControllers out of the storyboard by instantiating your storyboard into a UIStoryboard Object and getting the UIViewController via its identifier, here's how I do it:
hope this helps.
我发现最简单的方法是将项目从情节提要中复制并粘贴出来,一次一个视图,然后为每个视图重新创建视图控制器。
但是,对于执行此操作的任何人,请注意,除了所有其他 XIB 之外,您还必须为 MainWindow 创建一个 xib,并相应地连接它,包括设置窗口和应用程序委托。故事板为您处理所有这些,因此当您试图避免它们时,您需要进行大量手动设置,从一开始就为您创建非故事板项目。不要做我所做的事情,并尝试让你的根控制器成为你的主视图控制器,因为它会疯狂地说 UIApplication 与 XIB 的各个属性的键值不兼容。
I found that the simplest method was to copy and paste the items out of the storyboard, one view at a time, and recreate the view controllers for each one.
However, for anybody who does this, note that you have to make a xib for MainWindow in addition to all of your other XIBs, and hook it up accordingly, including setting up the window and app delegate. Storyboards handle all of this for you, so when you try to avoid them, you have a lot of manual setting up that creating non-storyboard projects from the get-go handles for you. Don't do what I did, and try to make your root controller your main view controller, because it will go nuts saying things about how UIApplication isn't key-value compliant for individual properties of your XIB.
正如其他一些人所建议的,最好的选择是将故事板中的视图克隆到 XIB 中。
As a few others have suggested, your best bet is to clone the views from storyboard into an XIB.
无法获取 xib 文件。您的故事板被编译为 nib 文件,并打包到应用程序包中的 Storyboardc 文件中。
要找到 nib 文件,请在 Finder 中选择构建的可执行文件,然后右键单击“显示包内容”。导航到 en.lproj 目录并找到storyboard.storyboardc 文件。再次右键单击故事板文件上的“显示包内容”,您将找到您的笔尖。但它们对您来说没有多大用处,因为它们是编译的二进制笔尖。
It's not possible to get xib files. Your storyboard is compiled to nib files and packaged into a storyboardc file within your app bundle.
To locate the nib files select your built executable in Finder and right-click 'Show package contents'. Navigate to the en.lproj directory and find the storyboard.storyboardc file. Right-click 'Show package contents' again on the storyboard file and you will find your nibs. They will not be much use to you though because they are compiled binary nibs.
您可能无法从情节提要中提取 .xibs,但请尝试此操作。打开基于 .xib 的项目并为您的视图创建空的 .xib 文件,同时打开故事板项目。选择故事板场景中的所有 UI 元素,然后将它们拖放到基于 .xib 的项目中。我已经以相反的方式完成了此操作(从 .xib 移动到情节提要),没有任何问题。
You may not be able to extract the .xibs from the storyboard, but try this. Have your .xib based project open and create the empty .xib files for your views and also have the storyboard project open at the same time. Select all the UI elements in your storyboards scene and simply drag and drop them over to the .xib based project. I have done this the other way around (moving from .xib to storyboard) with no problems.