如何制作 iPhone 和 iPad 版本的应用程序? [英] How to make iPhone and iPad version of an app?

查看:25
本文介绍了如何制作 iPhone 和 iPad 版本的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个适用于 iPhone 和 iPad 的应用程序.我正在寻找如何使两者兼容的界面.当应用程序加载时,我正在显示一个表格视图.如何根据设备加载不同的笔尖?我用它来切换笔尖.

I am trying to make an app which works on both iPhone and iPad. I am looking how to make an interface compatible on both. When the app loads I am displaying a table view. How can I load different nibs based on device? I am using this to switch between nibs.

if ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)]) 
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) 
        {
            device = @"iPad";
        }
        else 
        {
            device = @"iPhone";
        }

    }

但在 MainWindow.xib 中,它说视图是从 iPhone 的视图控制器加载的.我可以根据设备使这个动态吗?即我想从应用程序开始显示基于设备的不同笔尖.谢谢.

But in MainWindow.xib it says view is loaded from the view controller for iPhone. Can I make this dynamic based on device? ie I want to show from the start of app different nibs based on device. Thanks.

推荐答案

实际上,Apple 会自动完成所有这些工作,只需命名您的 NIB 文件即可:

Actually, Apple does all this automatically, just name your NIB files:

MyViewController~iphone.xib // iPhone
MyViewController~ipad.xib // iPad

并使用最少的代码加载您的视图控制器:

and load your view controller with the smallest amount of code:

[[MyViewController alloc] initWithNibName:nil bundle:nil]; // Apple will take care of everything

这篇关于如何制作 iPhone 和 iPad 版本的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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