Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
820 views
in Technique[技术] by (71.8m points)

xcode - How to start a project with both outputs iPhone & iPad?

Using the Pre Release Xcode 3.2.3 I get this as a Startup Project

alt text
(source: balexandre.com)

What should I chose / do to great a project that can have both iPad and iPhone as a target (not showing the iPhone App on iPad but a real iPad View)?

Thank you.


To avoid problems:

  • iPhone OS 3.1.3 is the latest release on iPhone
  • iPhone OS 3.2 is the latest release on iPad

My question does not infringe any agreements that me and Apple are bound to, as my question is regarding those already public Releases.

I just stated that on my Operating System I'm running the Xcode 3.2.3, that is all.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

just found out a simple way:

alt text http://www.balexandre.com/temp/2010-04-17_1242.png

alt text http://www.balexandre.com/temp/2010-04-17_1241.png

Then, if you want to switch to XIB files per device, let's say, the MainView for iPhone is A and the MainView for iPad is B, in your AppDelegate you add this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // The default have the line below, let us comment it
    //MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];

    // Our main controller
    MainViewController *aController = nil;

    // Is this OS 3.2.0+ ?
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            // It's an iPad, let's set the MainView to our MainView-iPad
        aController = [[MainViewController alloc] 
                              initWithNibName:@"MainView-iPad" bundle:nil];
    else 
            // This is a 3.2.0+ but not an iPad (for future, when iPhone runs with same OS than iPad)
        aController = [[MainViewController alloc] 
                              initWithNibName:@"MainView" bundle:nil];

    #else
        // It's an iPhone (OS < 3.2.0)
        aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
    #endif

    // Let's continue our default code 
    self.mainViewController = aController;
    [aController release];

    mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
    [window addSubview:[mainViewController view]];
    [window makeKeyAndVisible];

    return YES;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...