Dynamically load nib for iPhone/iPad within view controller

前端 未结 5 2101
悲哀的现实
悲哀的现实 2020-12-24 13:30

I have converted an iPhone application using the wizard like thing in XCode into a universal app.

It builds fine but obviously looks a bit rubbish in some areas :)<

5条回答
  •  渐次进展
    2020-12-24 14:22

    EDIT: @Adam's answer below is the correct answer.

    To determine which nib to load, do the following, and scrap your initWithMyLovelyData method and use a property to set the data. You should be able to easily move all your init code into the property setter method.

    MyViewController *viewController;
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        viewController = [[MyViewController alloc] initWithNibName:@"ipadNIB" bundle:nil];
    } else {
        viewController = [[MyViewController alloc] initWithNibName:@"iphoneNIB" bundle:nil];
    }
    
    viewController.myLovelyData = someData;
    

提交回复
热议问题