Search code examples
iphoneipadxcode4.2pushviewcontroller

how can i push appropriate XIB (Ipad or IPhone) without calling initWithNibName


I am trying to push controller using

but for the universal app

i have to write..

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];

}

Can i get solution to overcome the " if " condition and avoid the device check..


Solution

  • Make two nibs, one for iPhone and one for iPad name them MyViewController~iphone.xib and MyViewController~ipad.xib (note: it's important to match the case!). Make sure they're both added to your target, and then in your code just do:

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