如何将视图从 XIB 文件移动到 Xcode 项目中的故事板?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16601690/
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
How to move the views from a XIB file to storyboards in a project in Xcode?
提问by Manas
I am new to iOS programming and Xcode. I have a project which is working perfectly fine with 5 viewControllers
and XIB
file. I have to add many more features in it (like Google Maps, iAd Banner and others) so I am finding it difficult to manage it all. So I thought to use Storyboards in my project so that I can see more clearly as to what view is getting loaded after a certain action is performed. Now I have to move the views and the whole project into storyboards from the XIB files.
我是 iOS 编程和 Xcode 的新手。我有一个项目,它与 5viewControllers
和XIB
文件一起工作得很好。我必须在其中添加更多功能(例如 Google 地图、iAd Banner 和其他功能),因此我发现很难管理所有这些功能。所以我想在我的项目中使用 Storyboards,这样我就可以更清楚地看到在执行某个操作后加载了什么视图。现在我必须将视图和整个项目从 XIB 文件移动到故事板中。
I copied the 'view object' from the XIB files to Storyboard and just change the class name to the respective ViewController classes in the identity inspector. But that doesn't work. What more changes need to be done for this?
我将“视图对象”从 XIB 文件复制到 Storyboard,然后在身份检查器中将类名更改为相应的 ViewController 类。但这不起作用。为此还需要做哪些改变?
I checked out a few tutorials available on YouTube, but it didn't help much.
我在 YouTube 上查看了一些可用的教程,但并没有太大帮助。
Please let me know how this can be done. If possible please also give me any links to gain some knowledge which can help me achieve it.
请让我知道如何做到这一点。如果可能的话,还请给我任何链接以获得一些可以帮助我实现它的知识。
Thanks in advance.
提前致谢。
回答by Amit
You need to do more, i am listing basic steps you should do (it may vary from case to case):
你需要做更多,我列出了你应该做的基本步骤(它可能因情况而异):
- you can copy the view controllers from Xib and paste it to storyBoard , give the class name to these as to your ViewController classes. May be you need to connect again the objects and other connection in ViewController.
the method we use to instantiate a controller in case of Xib i.e.:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
will not be used anymore. Now you need ro connect the controllers with segue connections in the way it should be. Then instead of above method you need to use method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- 您可以从 Xib 复制视图控制器并将其粘贴到 storyBoard ,为这些视图控制器提供类名作为您的 ViewController 类。可能您需要再次连接 ViewController 中的对象和其他连接。
我们用来在 Xib 的情况下实例化控制器的方法,即:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
将不再使用。现在您需要按照应有的方式使用 segue 连接来连接控制器。然后,您需要使用方法而不是上述方法:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
to instantiate view objects then handle it accordingly.
实例化视图对象然后相应地处理它。
There will many other changes too based on your code but these are basic changes.
根据您的代码,还会有许多其他更改,但这些是基本更改。