roamingsoul
roamingsoul

Reputation: 93

how to do different coding for iphone and ipad in same .m file in universal app?

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!!!

Upvotes: 1

Views: 650

Answers (2)

TheTiger
TheTiger

Reputation: 13354

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!!

Upvotes: 3

Suhaiyl
Suhaiyl

Reputation: 1081

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

Upvotes: 4

Related Questions