How do I make my app universal? (3.5", 4", and iPad) - iphone

I'm brand new in Xcode and have been able to scoot by with some fairly simple apps thanks to my previous programming experience, the Storyboard in Xcode, and most of all THIS WEBSITE.
One thing I haven't been able to figure out is how to make my app universal? The way I have my app set up is that it looks a lot like the iPhone home screen with pages and app icons. However, when I hit the little "Change to iPhone 5" button, 1) It only changes my FirstViewController and 2)My icons are all out of alignment.
Do I make another storyboard (If so, how?)? Do I make another view controller for each screen resolution? For either of those questions do I program a test to see which device I'm using and for it to choose the correct storyboard or ViewController? My app is currently set to universal, but I still haven't even been able to find the iPad resolution option for view controllers and stuff.
Please be as simplistic as you can. I have only been doing this for an extremely short time. Thanks for all your help both here and around this site!

So In order to get the iPad version working, follow these steps:
First go to your target settings, scroll down to "Deployment Info", and change it from iPhone to Universal
Next you will need to create a new Storyboard file. On the bar at the top go File>New>File and this thing should pop up:
After you have selected iOS>User Interface>Storyboard as shown above, click next and it will ask iPhone or iPad. After selecting iPad, the new file will be ready to map your interface for iPad. However, you need to make sure the app uses it. So go back to your target settings and scroll back down to "Deployment Info" and switch to iPad:
Set the "Main Interface" option to the name of your new storyboard file.
As for preparing for iPhone 5, that part can get a bit annoying. I find that the additional space is too small for any major additions but too large to be ignored easily. How you deal with it will vary greatly depending on what you app does. From what you described, with app icons like the iPhone screen, you will probably want to have an additional row of icons, just like the iOS. To do this, you can either manage it programatically or you may want to have seperate storyboards for iPhone 4 vs iPhone 5. If you want the separate storyboards, this question will have your solution.

To initialize storyboard:
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
UIViewController *initialViewController;
if (iOSDeviceScreenSize.height == 480)
{
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:#"iPhone4" bundle:nil];
// Instantiate the initial view controller object from the storyboard
initialViewController = [iPhone35Storyboard instantiateInitialViewController];
}
if (iOSDeviceScreenSize.height == 568)
{
// iPhone 5 and iPod Touch 5th generation: 4 inch screen
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:#"iPhone5" bundle:nil];
initialViewController = [iPhone4Storyboard instantiateInitialViewController];
}
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
return YES;

Related

Upgrade iPhone-Only app to Universal doesn't create -ipad classes

I'd like to upgrade my iPhone-only app to Universal. So, from the targets' general window I switch from iPhone to Universal and select "copy" for generate iPad Storyboard based on the iphone one. Now a new folder named iPad is created but is empty and I can't find all of the -ipad classes. What I want is to have all of the original (iPhone) classes duplicated with the -ipad suffix and a iPad dedicated Storyboad. Starting from these classes, and from the iPhone logic I want create step by step a new ipad version. In the targets' general windows ipad main interface is main_iphone-ipad but in the project doesn't exist, in the folder neither.
This isn't an issue with Xcode, thats what its supposed to do.
You can certainly duplicate your entire project for the iPad version manually if you'd like, but I can't think of a case where you'd actually want to do this.
Most of the time you just want to change the View layer between the iPad and iPhone version. You can load a different Nib based on the device you'd like or even load completely different view controllers doing simple logic like
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
viewController = [[MyViewController alloc] initWithNibName:#"ipadNIB" bundle:nil];
} else {
viewController = [[MyViewController alloc] initWithNibName:#"iphoneNIB" bundle:nil];
}
** BEGIN EDIT **
To setup a different storyboard for iPhone/iPad all you need to do is create another storyboard and name it "myprojectname_ipad.storyboard" then in the Info.plist for your project add a key called "Main storyboard file base name (iPad)" with a value "myprojectname_ipad"
** END EDIT **

File's owner belongs to the wrong class

My iPhone app had the standard ViewController.h, ViewController.m and ViewController.xib to support the 3.5" retina display. I made a new ViewController_5.h, ViewController_5.m, ViewController_5.xib to support the 4" display on the iPhone 5. In theory, these should be totally independent of each other. But now, IBActions from the ViewController_5.h show up in ViewController_5.xib, and when I connect them I expect the action to carry out whatever is in ViewController_5.m. But it actually does the code in ViewController.m. What's going on here?
from the code you posted it looks like you just need to supply the right view controller class (ViewController_5) in the else part of your if statement, like this
... else { self.viewController = [[ViewController_5 alloc] initWithNibName:#"ViewController_5" bundle:nil]; }

integrating iOS4 project into iOS5 project

I have a newbie question about integrating two iOS apps. I have created an app in iOS 5 (my first app so I dont have any knowledge of iOS 4 except the fact thah there were xibs files instead of storyboard and also ARC was not included).
Now I have to include one older standalone app (built for iOS 4 with xibs and non ARC) to my iOS 5 app. Lets say that in my app on Main menu view there will be a new button opening the main menu of the other app.
So I did some research and find out how to disable ARC by the fno-objc-arc flag. Fine, now I have imported all the files of the second app to mine app and all the classes have the flag set.
I can still run my app without problem.
Now I have no idea how to let my new button to open the mainViewController of the old app - this app has MainWindow.xib (contains a window and one navigation controller). This MainWindow is set to be Main Interface in the old project. There are also some init call in appMainDelegate file. Where can I call them in my app?
Could anybody tell me what needs to be done. I have an idea, that I will add only one new UIViewController to my storyboard. This will be the starting point for the old app and than everything will work as it used to. Or will I have to create more controllers (for every xib) in my storyboard? This is where I dont know what to do. Any help much appriciated. thank you
Try doing something like the following, anything like it or simmular should work:
In the method of the button (the one you call your new button) have it execute the following code:
OldAppMainViewController *controller = [[OldAppMainViewController alloc] init];
//Here you can assign vallues to any properties that you might want to
[self.navigationController pushViewController:controller animated:YES];
That old apps main view controller should have a init with nub named function so it should work. If this does not work try something along the lines of:
OldAppMainViewController *controller = [[OldAppMainViewController alloc] initWithNibName:#"OldAppMainViewController" bundle:nil];
Where the NIB name is the .xib file name without the extension.
Also make sure that all connections in interface builder is setup correctly

How to handle views?

How can I handle different views in XCode?
Let's say I want to show a different view when the user press a button.
UIViewController *viewSettings;
[viewSettings initWithNibName:(NSString *)#"SettingsViewController" bundle:(NSBundle *)nil];
This code don't work. The app crashes.
I have updated my XCode to the new version. How can I say my projects that they have to take the new SDK?
Thanks.
This is the correct line. Then you need to push it (pushViewController) onto a UINavigationController or add it to an existing view. Do a Google search for iPhone Beginner Tutorial First Application or something like that.
UIViewController *viewSettings = [SettingsViewController initWithNibName:#"SettingsViewController" bundle:nil];
1) You use a UIViewController to manage the view stack and ultimately which view is visible.
2) In your xCode project, modify the project or target "Base SDK" property. This will let you choose the minimum version of iOS to require of your users.
You need to read the Apple documentation for view controllers There are also some very good beginner books out there for iPhone programming

can TTURLMap from three20 map to a xib-file?

ive made an app for the iphone and wanted to make it work on an ipad too.
for the navigation i used three20. all the views are viewcontrollers with xib´s.
for later developement, i just wanted to make the xibs in the bigger format as new skin and let the background-programm the same, so that in the end each viewcontroller would have 2 xib´s as skins.
so, three20´s URLMap can link to class-files. but how can i link to a xib ?
i wanted in the appdelegate to make the URLMap depending on the device, so that the programm it self can stay as is with its URL-Calls.
ok, now i used to overwrite the initWithNibName in combination with [UIDevice currentDevice].model to let the viewcontroller check, on which device he loads