如何在不调用initWithNibName的情况下推送适当的XIB(Ipad或IPhone)

时间:2012-09-12 13:12:10

标签: iphone ipad xcode4.2 pushviewcontroller

我正在尝试使用

推送控制器

但适用于通用应用

我必须写..

if([[UIDevice current]UserInterfaceIdiom] == UIUserInterFaceIPad)
{
    MyViewController *controller = [[MYViewController alloc]initWithNibName:@"MyViewController_IPad"];


    [self.navigationCOntroller pushViewController:myViewController animated:YES];

    else{
    MyViewController *controller = [[MYViewController alloc]initWithNibName:@"MyViewController_IPhone"];


    [self.navigationCOntroller pushViewController:myViewController animated:YES];

}

我可以获得解决方案来克服“如果”  条件并避免设备检查..

1 个答案:

答案 0 :(得分:2)

制作两个笔尖,一个用于iPhone,另一个用于iPad,将它们命名为MyViewController~iphone.xibMyViewController~ipad.xib(注意:匹配案例非常重要!)。确保它们都已添加到您的目标中,然后在您的代码中执行:

MyViewController *controller = [[MYViewController alloc]initWithNibName:@"MyViewController"];
[self.navigationCOntroller pushViewController:myViewController animated:YES];