1

I have created app for iPhone. I have no of table views, image views, map views in my app. All data coming through web service. And I've given some static sizes for image and other views through coding. now, I need the same app for iPad. So i have to change coding of view sizes for Ipad. I need to do different coding for iPhone and iPad in the same .m file. Anyone pls suggest me how to do that!!!

roamingsoul
  • 93
  • 2
  • 12
  • See my answer here: http://stackoverflow.com/questions/7217277/what-is-the-code-to-detect-whether-ios-app-running-in-iphone-iphone-retina-disp/7223662#7223662 – Luke Jun 09 '12 at 10:20
  • http://devimages.apple.com/iphone/resources/introductiontouniversalapps.pdf – Sergey Kalinichenko Jun 09 '12 at 10:39

2 Answers2

4

Till i understood your question, i think this is what u need:

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

and you can refer to this post : http://iphonedevelopment.blogspot.in/2010/04/converting-iphone-apps-to-universal.html

Suhaiyl
  • 1,071
  • 9
  • 17
3

As you can see when you choose a universal app in the starting when you are taking a new project - in universal app Appdelegate.m file the apple provides the code for that.

see this -

- (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;
}

by same method you can distinguish the iPad and iPhone. Thank You!!

TheTiger
  • 13,264
  • 3
  • 57
  • 82
  • 1
    currently no need to specify the two different nib names, the nib file for ipad should have convention of "~ipad" after the name (ViewController and ViewController~ipad), rest IOS takes care of. I think this is easy to maintain \m/ – Suhaiyl Jun 09 '12 at 14:13
  • 1
    @Suhaiyl - read my last line please. i just give the hint. and i think my code is describing what the user roamingsoul want. – TheTiger Jun 09 '12 at 14:16