1

我已经为 iPhone 创建了应用程序。我的应用程序中没有表格视图、图像视图、地图视图。所有数据都来自网络服务。我已经通过编码为图像和其他视图提供了一些静态尺寸。现在,我需要相同的 iPad 应用程序。所以我必须更改 Ipad 的视图大小编码。我需要在同一个 .m 文件中为 iPhone 和 iPad 进行不同的编码。任何人请建议我如何做到这一点!

4

2 回答 2

4

在我理解你的问题之前,我认为这就是你需要的:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    // place the iphone code
}
else 
{        
   // place the ipad code
}

你可以参考这篇文章:http: //iphonedevelopment.blogspot.in/2010/04/converting-iphone-apps-to-universal.html

于 2012-06-09T10:44:41.403 回答
3

正如您在开始新项目时选择通用应用程序时所看到的那样 - 在通用应用程序 Appdelegate.m 文件中,苹果提供了代码。

看到这个——

- (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 = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

通过同样的方法你可以区分 iPad 和 iPhone。谢谢你!!

于 2012-06-09T12:37:37.150 回答