How to add xib for iPad - iphone

I have created my app for iPhone and I have one xib. If I run my app on iPad simulator, it appears in left top corner.I want to add one more xib for iPad so that when I run iPhone simulator it will run iPhone xib and when i run iPad simulator it will run iPad xib. How can I do that?

To create only a Xib file just follow this.
FIle->New ->File...
In the window that appears click the User Interface under IOS u can see a Empty UIBuilder file.
click it then click next and give it the appropriate classfile name for ipad or iphone

First create a new xib for IPAD and while giving the name of the nib file provide the XIB file name created for IPAD.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
HomeScreenController *homeScreenController = [[HomeScreenController alloc] initWithNibName:#"HomeScreenController" bundle:nil];
[self.navigationController pushViewController:homeScreenController animated:YES];
}else {
enter code here
}

Related

Making universal build for iphone application with xcode 4.51

I had an old project which uses XIB for each UIViewControler.That was intended for I Phone but now I want to make that project with universal build that is for Iphone as wall as IPad also.The problem is that when I changed the build type to Universal and used coding like
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
// ipad coordinates
}
else
{
//iphone coordinates
}
this the display is correct on iphone and ipad but on ipad the buttons are not taking click event on entire button but only on a small portion of button.Though I am not loading Nib but it is taking crated iphone xib file internally and I think thats why it's button behavior is not in accordance to ipad view. I am confused that what I should do?How to make copy of XIB for Ipad and load them depending upon device.It is to mention here that I am not loading any nib from my code but It is being called internally. Please help
For universal app you can make 2 xib
1 - > yourView_iPhone
2 - > yourView_iPad
And load each xib according yo your idiom
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
yourView *obj = [[yourView alloc]initWithNibName:#"yourView_iPad " bundle:nil];
// ipad coordinates
}
else
{
yourView *obj = [[yourView alloc]initWithNibName:#"yourView_iPhone " bundle:nil];
//iphone coordinates
}

iOS - Converting iPhone Build to iPad

I have a application that I built that was to be build as an iPhone-only application.
Now, I am told that the application has to be made universal now. I will have to make it iPad compatible too (in portrait-only mode). I have been looking for my options right now as the XIBs in this project are heavily loaded with objects so programatically assigning co-ordinates will be a pain.
I am looking for the best, and the quickest approach I should take to make this iPhone app into iPad-compatible app as well.
PS: There is no mainwindow.xib file as the application was built with XCode 4.3 which doesn't create the MainWindow.xib file.
Thank you in advance.
EDIT: I have made duplicate XIBs for iPad for all the XIBs. Now, I am trying to use the naming convention which tells me to change the filename suffix to MyiPadXIB~ipad.xib and when the app is run on iPad, it will automatically take that XIB. This doesn't seem to be happening.
When I open the application in iPad, only a small window appears (the window that appears when iPhone-only app is run on an iPad).
Any solution to this?
I followed a very easy approach where I would just create duplicate XIBs of all the XIBs by doing Build settings > target (iPhone)> right click and choose duplicate.
I would then change the name of the duplicate xibs in this format: "iPhone XIB name"~ipad.xib.
The system would then automatically pick up the XIB according to the device used.
From what I know (there may be a quicker/better approach that i dont know of)
You would create seperate xib files for the ipad
when you init your view controller you check to see what device you are on like so
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.serverSettingsViewController = [[ServerSettingsViewController alloc] initWithNibName:#"ServerSettingsViewController_iPhone" bundle:nil];
self.motionJpegViewController = [[MotionJpegViewController alloc] initWithNibName:#"MotionJpegViewController_iPhone" bundle:nil];
} else {
self.serverSettingsViewController = [[ServerSettingsViewController alloc] initWithNibName:#"ServerSettingsViewController_iPad" bundle:nil];
self.motionJpegViewController = [[MotionJpegViewController alloc] initWithNibName:#"MotionJpegViewController_iPad" bundle:nil];
}
And load you iphone or ipad xib file (FYI make sure the xib views are large enough for the ipad)

Creating universal app for Xcode 4.3?

I am little bit confused about creating universal application for iOS devices using Xcode 4.3 , later versions (Xcode 4) have separate folder classes for this, but how will we make this using newest version of Xcode?
Thanks in advance
I don't think this has changed in Xcode 4.3 compared to previous versions of Xcode 4.* , but though you have a doubt refer to my answer below.
If you want to create a new project as Universal App then select Universal in Device Family in below image:
Or if you are trying to convert an existing iPhone or iPad app to Universal app then select Devices as Universal from Target Settings- > Summary Tab, set Devices to Universal:
Hope this helps you.
EDIT:
Let us suppose View Controller name is YourViewController
Let us suppose name of iPad XIB is YourViewController-iPad.xib and iPhone xib name is YourViewController.xib
YourViewController *yourViewController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //This is iPad
{
// iPad-specific interface here
yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController-iPad" bundle:nil];
}
else // This is iPhone or iPod
{
// iPhone and iPod touch interface here
yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
}
Let me know if you need more help.
just select device family as universal while creating the project,
watch this screen shot
well you need to create two xib's, one for iPhone and one for iPad and just use
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
here open your iPad xib
} else {
here open your iPhone xib
{

Adding iPad XIB/VIEW to a "View Based Application" in iOS 4

I've created a View Based Application in XCode4 and trying to do the code and UI design according to the way Apple have intended it to be.
So I designed the UI in the AppNameViewController.xib and it works fine; now I want to enable it as a UNIVERSAL application that runs on iPad as well. I changed the App-Target>>Summary>>Devices from iPhone to Universal and miraculously XCode had automatically created MainWindow-iPad.xib (Apple, very nice...), but since I designed the application first screen on the AppNameViewController.xib and not on the MainWindow.xib when I run the app on iPad Simulator I get this ugly screen where my UI objects size and location is distorted (their size is still set for iPhone so they are all crumbled on the left-top corner of the screen).
In my previous app I used the code appearing below to distinct between the AppNameViewControllerForIPHONE.xib and the AppNameViewControllerForIPAD.xib; It was done from the AppDelegate.m file, but in the new XCode View Based Application template the AppDelegate doesn't go through initWithNibName method at all.
Code I used on XCode 3 that cannot be used on XCode 4:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
viewController = [[AppViewController alloc] initWithNibName:#"AppViewControllerIPAD" bundle:[NSBundle mainBundle]];
}
else {
viewController = [[AppViewController alloc] initWithNibName:#"AppViewControllerIPHONE" bundle:[NSBundle mainBundle]];
}
Long question... still, anyone had any idea how it should be done here? Where should I design the iPad UI or is there a way to easily transform the iPhone xib to an iPad one?
You have to follow the new naming scheme (idiom in Apple-speak) specified for Universal Applications for the NSMainNibFile key in your info.plist. For example, if you set your NSMainNibFile to be "MainWindow-iPhone", the xib for ipad would be "MainWindow-iPad".
The same naming convention should hold for the views in a view based application (I can't test right now, installing new xcode).

How to make iPhone and iPad version of an app?

I am trying to make an app which works on both iPhone and iPad. I am looking how to make an interface compatible on both. When the app loads I am displaying a table view. How can I load different nibs based on device? I am using this to switch between nibs.
if ([[UIDevice currentDevice] respondsToSelector:#selector(userInterfaceIdiom)])
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
device = #"iPad";
}
else
{
device = #"iPhone";
}
}
But in MainWindow.xib it says view is loaded from the view controller for iPhone. Can I make this dynamic based on device? ie I want to show from the start of app different nibs based on device.
Thanks.
Actually, Apple does all this automatically, just name your NIB files:
MyViewController~iphone.xib // iPhone
MyViewController~ipad.xib // iPad
and load your view controller with the smallest amount of code:
[[MyViewController alloc] initWithNibName:nil bundle:nil]; // Apple will take care of everything
You can do that in a similar way:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
mainMenu = [[MainMenu alloc] initWithNibName:#"MainMenuiPad" bundle:nil];
}else{
mainMenu = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
}
For making universal app,
1-set target family in info build tab for app as iPhone/iPad.
2- Delete window from main window.
3- Add two xib one for iPhone and one for iPad(by selecting iPad xib).
4- make appDelegate class as controller file for these xib's.
5- Add window on these xibs and view controller or navigation controller and by IB Inspector set load nib name and controller file here which one is your first view.
6- And then make differnet xib for iPad and iPhone which having tableview or other controls.
7-Make single contoller file or different controler file for different device for same you need to check the device by this if else condition
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
8-Now you need to load xib in appDelegate class in method didFinishL--
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
// load your nib for iPad here which having view controler or navigation controller as well window.
}else{
//load nib for iPhone.
}
Try this in your Info.plist:
Main nib file base name [NSMainNibFile]: MainWindow_iPhone
Main nib file base name (iPad) [NSMainNibFile~ipad]: MainWindow_iPad
I hope this helps you.