简体   繁体   English

如何为iOS中的通用应用添加新的XIB文件?

[英]How to add new both XIB file for Universal app in iOS?

When I create Universal app in my project start, XCode automatically create ViewController class and XIB File for both iPhone and iPad like 当我在项目开始时创建通用应用程序时,XCode会自动为iPhone和iPad创建ViewController类和XIB文件,例如

ViewController.h
ViewController.m

ViewController_iPhone.xib
ViewController_iPad.xib

I need to add another Class with both iPhone and iPad XIB Files. 我需要为iPhone和iPad XIB文件添加另一个类。 But when I create new file in XCode , I can only choose XIB file for one thing. 但是,当我在XCode创建新文件时,我只能为一件事情选择XIB文件。 If I checked Targeted for iPad checkbox, i can get only XIB file for iPad. 如果我选中了“针对iPad的目标”复选框,则只能获得针对iPad的XIB文件。

I want to add both iPhone and iPad XIB with class. 我想将iPhone和iPad XIB都添加到类中。 How can I do that? 我怎样才能做到这一点?

You just need to link your ViewController of iPad in inspector like following. 您只需要在检查器中链接iPad的ViewController,如下所示。

To link a .xib to a class with Xcode4: 要将.xib链接到使用Xcode4的类:

Open your new added iPad .xib. 打开新添加的iPad .xib。

In the placeholder select File's Owner. 在占位符中,选择“文件的所有者”。

In the third thumbnail choose "Identity Inspector" in right panel, and then edit the "Custom Class" field and enter your class name like (SecondViewController). 在第三个缩略图中,在右面板中选择“身份检查器”,然后编辑“自定义类”字段,然后输入您的类名称,例如(SecondViewController)。

After that you will be okay with XIB file. 之后,您将可以使用XIB文件。

I think my answer can help you. 我认为我的回答可以为您提供帮助。

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

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