IOS: app universal concepts - ios

I'm starting a project that must be for iPhone and iPad...you can tell me that it's easy and that I can create an "Universal" project..it's right.
But I have a "stupid" question about a "stupid" problem.
In an universal project I have two .xib (iPhone and iPad) for a class and inside code I verify if I'm using the one or the other
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
}
else
{
// The device is an iPhone or iPod touch.
}
ok?
But you know that in a single view of iPad I can show many views that an iPhone can show one at time.
At example I have two view with their classes:
FirstView.h-FirstView.m-FirstView_iPad.xib-FirstView_iPhone.xib
and
SecondView.h-SecondView.m-SecondView_iPad.xib-SecondView_iPhone.xib
For iPhone it's not a problem but for iPad? In a view in iPad I can put first and second viewcontroller, it's not easy to organize if I have two different classes for two viewcontrollers... Do you have a solution for this? Or the best solution is crate two separate project iPhone and iPad?
thanks

So yeah I always use one theViewController.h and one theViewController.m and I have a theViewController.xib for iPhone and a separate xib for iPad only. if you name the iPad xib ending with theViewController~ipad.xib the OS will automatically recognise the XIB. You will have to set the class of the theViewController~ipad.xib in Interface builder in the inspector area to the same class as your iphone xib i.e the class would be called theViewController then you can connect up what ever outlets you have defined in your .h and .m also the great thing about just naming the iPad xib to ending with ~ipad.xib when you push views you dont have to check the idom before pushing as the OS recognises the ~ipad.xib extension and pushes the correct view depending on device..hopefully this is helpful for you!

Related

iOS - Open a different Stroryboard based on the device size

I have created an app in Swift and I want it to be available in both iPhone and iPad, but I would like the iPad to have a couple different layout variables, such as bigger buttons and pictures. Using auto-layout or Size Classes with constraints wasn't working and not letting me put them where I want them, so I was wondering how to make it so that when I open the simulator with an iPad, it opens the storyboard with the different View Controller layouts. I made a duplicate storyboard so I have main.storyboard and the copy is mainiPad.storyboard for the iPad only. If this can be done, please let me know! Thanks!!
This Tutorial is the old way, when You simply add iPad suffix in the file name.
This Post is the new way, introduced in Xcode 6; You simply select the storyboard name for ipad and iphone family in application plist file.

Make an application work on both iPhone and iPad

I would like to make it so that my iPhone app also works on iPad.
If I run it using the iPad simulator it does work, but the app doesn't show up on the iPad app store, and looks really weird.
Is it possible to create another .xib file for the iPad? I know how to add a new iPad .xib file, yet I don't know how to actually change the RootViewController.xib to RootViewController_iPad.xib if the device being used is an iPad.
I already have code for finding out if the device is an iPad, and I don't want to use auto-layout, because I would like to add different things to the view if they are using an iPad (such as using different images).
I would like to make it so that my iOS applications look good on both iPhone and iPad, and have a separate .xib files for each. Is it possible to change the default .xib file from RootViewController to RootViewController_iPad?
In order to make an application work in both iPhone & iPad then need to follow below steps.
Before create an project please select universal in device section.
In application: didFinishLaunchingWithOptions: put a condition to check the device.
If the device is iPad then load the iPad screen and if the device is iPhone then load the iPhone screen.
Make sure follow the MVC pattern, So that it is easy to populate the data in both the screens.
#class has no effect on outlets or actions it only tells the compiler that there is a class with the name that follows, no information about properties, or methods is included.
If you want to have a xib for the iPad don't create a new class for it, just create a new xib and set the file's owner to be the same as the what owns iPhone xib. You then need to add a check in application: didFinishLaunchingWithOptions: to load the correct xib.
The best option though is to tell Xcode you want a universal app when you create the project.
The key point here is that it must be a UNIVERSAL application. Its a setting when you set the app up for the 1st time. You will end up with 2 UI's (story boards or xib files).
You will have to create 2 seperate UI's for ipad and iphone. You may be able to use the main class itself for most of the code but then you have to basically put code that says
if its iphone.....
if its ipad ......

Universal Storyboard?

In the old XIB world of iOS development, I was able to create one View Controller and one XIB, and use them for both the iPhone and iPad environments. With just a few code tweaks, the XIB would resize and adjust to fit the different dimensions and aspect ratios. This allowed me to reduce the risk of the two layouts getting out of sync over time.
Is the same thing possible in the world of Storyboards? By default Xcode creates two distinct storyboards for my Universal app -- one for the iPhone and one for the iPad.
How can I use one storyboard for both?
Thanks!
Updated:
Size Classes in Xcode 6 will essentially achieve the goal of Universal Storyboards. More info here:
https://developer.apple.com/library/prerelease/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_6_0.html
In short...you can't.
There's a workaroud I use to create the iPad storyboard at the end of the iPhone development.
You have to locate the iPhone story board and using the Terminal you can duplicate it giving it the name of the iPad storyboard that Xcode has created for you. Delete the empty old storyboard and open the newly copied one changinge the targetRuntime attribute to "iOS.CocoaTouch.iPad" instead of the old value "iOS.CocoaTouch".
Open the iPad storyboard with Xcode, everything is there but it still needs to be arranged and connected to the ViewController (wiring stuff included..). It's not perfect but I usually do it to save some error prone copy and paste (and several hours as well).
If you just want to target your app for iPhone and deliver it to iPad you can just use the iPhone Xib and you'll get the 2x little botton in your right corner.
Update late 2014 (after Xcode 6 beta release)
Xcode 6 now allows you to define a single storyboard and through the size classes concept, to make it adapt to all their devices. This solution is a bit confusing (especially if you're familiar with how this problem is solved in the Android environment) but it's something in the right direction IMHO.
Yes you can.
You can simply select the very same storyboard in Xcode under General/Deployment info
I have a few app which have that.
They share a lot of view controllers.
If you use freeform size than you can create separate view controller in the story board and two separate segues.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self performSegueWithIdentifier:#"Open VC" sender:sender];
} else {
[self performSegueWithIdentifier:#"Open VC iPad" sender:sender];
}
Only disadvantage is that you cannot use iPad specific controls directly from the storyboard (popover etc.) unless you switch to an iPad storyboard

Create universal app using iOS StoryBoard that have different UI

I'm new with iOS and yesterday i learnt about storyboard. it works great. i refer to this link. I tried to create iPhone apps with a storyboard.
But now i want to create an universal apps, that means for iPhone and iPad. but also using the storyboard. lets say if i have the same UI, that wont be an issue. Same UI means, my iPhone UI using tab bar controller, my iPad also use a tab bar controller. I just need to point to the same class, and the result will be the same. Now, i want have a different UI. my iPhone will use a tab bar, but my iPad will use a split view.
here is my question :
is that possible to do that with device target universal? i mean iPhone with tab bar, iPad with split view.
if yes, how can i know which device is running? either i choose iPad or iPhone. How can i know i run on iPhone/iPad? what should I validate in the appdelegate?
For ipad storyboard, i drag a split view controller but i can't see any master detail whenever i run the apps. how can it be like that?
thanks. :)
If you create a Universal application (an application that supports both iPhone and iPad), Xcode will by default give you two Storyboards - one for iPhone, one for iPad. Under your target's settings you'll see a place where you can configure which Storyboard presents the main interface - you can set this separately for iPhone and iPad:
The OS will take care of loading the correct Storyboard for you.
If you want to detect in code whether you're running on an iPhone or iPad, you can use USER_INTERFACE_IDIOM(). For example:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
There's also UIUserInterfaceIdiomPad for iPad.

IOS - when I make a new Objective C class, what will checking "made for iPad" option do?

I am making a new Objective C class and it gave two options as check boxes:
1) Targeted for iPad
2) Make an XIB interface
What if I want to make an app that would work on both iphones and ipads? Can I do that or will I essentially need to re-do the app, so if I am testing it out on the phone first, I should not check that box? Or will that box just make things compatible with the iPad?
Also, for the XIB interface - its where I can place the ui elements, right? But can I place the UI elements on the button right from the storyboard?
Thanks!
As far as I know it will create XIB files for iPhone and for iPad screen sizes.
You don't need to make 2 apps, you can use 1 App logic for both and just change the views.
Few notes
This is one places were the MVC is important.
In the project summery on xcode you should mark the app as universal.
an other few lines that can help you are:
+ (BOOL)isDeviceAniPad {
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}
You can use this code to check the user device any time your code needs to perform different operations for iPhone and iPad.
An other option will be to create 2 Targets - one foe iPad and one for iPhone and let the targets share the same code.
Yes, XIB interfaces, like storyboards, are where you can interactively drop the UI elements. XIBs are a more primitive version of storyboards (which came in with iOS 5), but at the same time if you're working on a project with many hands and developers working on a single project, or lots of screens and view controllers (which would make for a very hefty & unwieldly storyboard), it may be worthwhile to stick with xib files.
If you select "Targeted for iPad", you may only get a storyboard sized for iPad-sized screens.
If you select "Make a XIB interface", your new class will be using xib files instead of storyboards.

Resources