用于 ipad 和 iphone 的 MainWindow.xib [英] MainWindow.xib for ipad and iphone

查看:21
本文介绍了用于 ipad 和 iphone 的 MainWindow.xib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以此为基础demo 包含 MainWindow.xib 和 ImageManipViewController.xib .但是我的应用程序在 AppDelegate.m 中包含以下代码,而我的应用程序(还没有?)包含 MainWindow.xib.对我来说,添加 2 个 MainWindow.xib 文件(一个用于 iPhone,一个用于 iPad)是否更好/最好(在我的方法中调用,每个文件都调用自己的 xib 文件)还是 MainWindow.xibs 只是额外的?

I am trying to build on this demo which contains both a MainWindow.xib and a ImageManipViewController.xib . But my app contains the following code in the AppDelegate.m and my app does not (yet?) contain a MainWindow.xib. Is it better/best for me to add 2 MainWindow.xib files (one for iPhone and one for iPad) too (that are called in my method, each calling its own xib file) or is are the MainWindow.xibs just extra?

(顺便说一句,如果结果是 MainWindow.xibs 是多余的,那么你能说为什么在原始演示中使用它吗?这可能只是作者简化步骤的结果例如,创建演示?)我还没有找到直接联系作者的方法.

(Btw, if it turns out that the answer is that the MainWindow.xibs are redundant, then can you say why it might have been used in the original demo? Was it likely just a result of the author simplifying the steps in creating the demo, for example?) I have not found a way to contact the author directly.

如果有更好的方法来开发通用"应用程序,请告诉我.

If there is a better approach to developing a "universal" app, please advise me.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPad" bundle:nil];
    }
    self.window.rootViewController = self.viewController;

推荐答案

您可以以编程方式或使用 Xib 文件构建主窗口及其附加的子视图(甚至视图控制器).结果是一样的,但小型演示项目通常使用 Xib 文件,以简化代码并专注于他们想要向您展示的部分.

You can build your main window and its attached subviews (and even view controllers) either programmatically or by using a Xib file. The result is the same, but small demo projects often use Xib files in order to simplify the code and focus on the part that they want to show you.

两个 Xib,一个用于 iPad,一个用于 iPhone,非常好,因为鼓励 iPad 应用程序使用可充分利用 iPad 大屏幕的视图;因此,建议将它们保存为单独的文件.不过,您的模型和控制器应该对 iPad 和 iPhone 通用.

Two Xibs, one for iPad and one for iPhone is perfectly fine because iPad apps are encouraged to use views that make the most of the iPad large screen; for this reason, keeping them as separate files is recommendable. Your model and controllers should be common to iPad and iPhone, though.

关于加载 Xib,如果您的项目面向 iOS 4.0 或更新版本,您可以将您的 xib 文件命名为BSViewController~iphone.xib"和BSViewController~ipad.xib"并避免代码中的一些条件:

And about loading Xibs, if your project is targeting iOS 4.0 or newer, you can name your xib files "BSViewController~iphone.xib" and "BSViewController~ipad.xib" and avoid some conditionals in your code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
}

这篇关于用于 ipad 和 iphone 的 MainWindow.xib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆