0

I am Creating a Universal App for both Iphone and Ipad. But i don't need to have same class for both Iphone and Ipad. I need to have a separate classes for each Iphone and Ipad. Can any one give me idea How to do that? I already created my app using Xcode 4. But When i create a new project in there, its generating One class file and Nib for both devices. I don't need to have it in that way for my purpose.

EX : I need this kind of classes files for both devices

IphoneviewController.h
IPhoneviewController.m

IPadviewController.h
IPadviewController.m

one Xib

UniversalviewController.xib

Thanks and looking for a quick replies.

Sameera Chathuranga
  • 3,638
  • 3
  • 27
  • 48
  • It is not good idea to have common xib file for iPhone/iPad as both have different sizes and it will create problems for you to maintain design consistent. – Janak Nirmal May 03 '12 at 06:00
  • Yeah I know but the customer want it that way ... – Sameera Chathuranga May 03 '12 at 06:52
  • well that look like you are going against the MVC rules. 2 view controllers one view? conflict between 2 controllers, which should control the view? – Hashmat Khalil May 03 '12 at 07:27
  • Yeah its little against the MVC rules. But it should have to have a way to detect the device type and detect the classes according to it. If its Ipad we can assign relevant class to the nib and same for the iphone. – Sameera Chathuranga May 03 '12 at 07:33

2 Answers2

0
BOOL isIPhone = (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad);

just judge it then use your seperate class to display different view

add:

sorry , i don't use any xib|nib to build my app, i use pure code but i think you can not use one xib with 2 viewcontroller

just create 2 xib for each viewcontroller or combine the code into one viewcontroller like the code above

adali
  • 5,977
  • 2
  • 33
  • 40
0

How about doing the following in your applicationDidFinishLaunch:

UIViewController * viewController;
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
  viewController = [[IphoneviewController alloc] initWithNib: "UniversalviewController"];
} else {
  viewController = [[IPadviewController alloc] initWithNib: "UniversalviewController"];
}
//now use your VC however it is appropriate for your app, such as...
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

By the way, with regard to the MVC discussion, assuming you need two different viewControllers for the two platform, you can share common code by creating a shared class with almost everything in it, import it to each, and then only implement or override anything that needs to be specific to the iPad in the ipad's specific version.

Here's the .h of your IPadviewController for example...

#import "viewController_Shared.h"

@interface IPadviewController : viewController_Shared {

}
mackworth
  • 5,873
  • 2
  • 29
  • 49