Question

am a noob at universal apps so please help me out and let me know if this can be done, I am creating a universal app and for doing this i have written the code and made the settings in each of my view controllers present in the iPhone and iPad group and at runtime i am identifying the device whether its iphone or ipad i am using the below method

 if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        myiPad_View *ipadObj = [[myiPad_View alloc]init];
        [self.window addSubview:ipadObj.view];

    }
    else
    {
        myiPhoneView *obj = [[myiPhoneView alloc]init];
        [self.window addSubview:obj.view];
    }

Now the query is my boss is eating my head for this he is telling me that can we write just one class and at run time when the app will be launched either in iphone or ipad device or simulator the view controller will adjust the frames accordingly i have done this by using the above method but he says if you do like this then the code will increase and you have to suffer a huge headache so actually he is right but haven't found of any alternate solution to this, so before saying this cant be done i thought of taking some expert advice

Was it helpful?

Solution

Your above method is actually how I determine devices in some of my apps as well.

I actually recently wrote a little piece on this issue.

You can also use:

#define IDIOM    UI_USER_INTERFACE_IDIOM()
#define IPAD     UIUserInterfaceIdiomPad
#define IPHONE   UIUserInterfaceIdiomPhone

if ( IDIOM == IPAD ) 
    NSLog(@"Device is iPad.");
else 
    NSLog(@"Device is iPhone or iPod touch.");

or

if ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] ) 
{
    NSLog(@"Device is an iPod touch");
    /*  same goes for "iPhone", "iPad" etc.  */
}

OTHER TIPS

I have 3 sets of classes:

  • base classes: this is where the shared logic goes
  • iPhone classes: iPhone specific logic including UI goes here
  • iPad classes: iPad specific logic, including UI goes here

I have as much as possible in the base classes, but for the times when the logic is separate, it is much easier to have the distinct classes. Digging through the code looking for the exceptions would be a pain, IMO.

I found this blog helpful (not mine)

Its not a problem . you have to create a universal app.

File--->New Project--->windowsapplication

and then choose a product Universal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top