Auto-resize iPhone xib app to ipad - iphone

I built an iPhone app "using xib" with 5-6 screens. Now I want to auto-resize the display for iPad. I am using xcode 4.6.
Do I have to rebuild the entire code using storyboards? It will be a very tedious work. Is there any solution for this?

You'll need to create only new xib files for iPad and name them as ViewController_iPhone.xib and ViewController_iPad.xib and when switching your views, just put a simple condition
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPad" bundle:nil];
} else {
ViewController *viewController = [[ViewController alloc] initWithNibName:
#"ViewController_iPhone" bundle:nil];
}

use autolayout and everything will be done automatically
if not autolayout, then making 2 xib will be a better option. Make ipad size xib with the same name and put ~ipad after classname.
Like if you xib name is myClass.xib and create other one like myClass~ipad.xib.

Related

IOS - Load a sub-controller/view into a View

I'm working on an iPad app (actually, converting a iPhone app into iPad app). Since I can put two "Iphone screens" on one "iPad screen" (just regarding the space), I have my iPad view 50% occupied by my original view (loaded through my main controller).
(so far so good)
Now, on the remaining 50% of the iPad view, I want to include another View (for which I have a controller and a view, iphone-sized). I tried to add a "View" component, but how do I load another controller into it ? is that even possible ?
MainViewController loading MyView1.xib
I want to load, in the "View" component, MySecondaryController, loading MyView2.xib
http://imageshack.us/photo/my-images/835/d8fs.png/
Thanks
you can do it something like below...write below code in function which is in Mainviewcontroller(for example on some button tap)
yoursecondviewcontroller *objDate = [[yoursecondviewcontroller alloc] initWithNibName:#"yoursecondviewcontroller" bundle:nil];
objDate.delegate = self;
UIPopoverController *datePopOver = [[UIPopoverController alloc] initWithContentViewController:objDate];
datePopOver.delegate = self;
[datePopOver setPopoverContentSize:CGSizeMake(320,393)];//give any size you want.
[datePopOver presentPopoverFromRect:CGRectMake(50,700, 320, 393) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];//give size and origin whatever you want in FromRect .....
You can also define UIPopoverController object in .h file....
and don't forget to set delegate of UIPopoverController that is UIPopoverControllerDelegate
Let me know it is working or not!!!
Happy Coding!!!!

upgrading iPhone app to universal and now using splitview

I have an iPhone app that works and is getting used. I now want to upgrade this application to a Universal app. Taking that into consideration I've already made changes, like creating another MainWindow.xib for the iPad, which i've gotten to work. I've pretty much got the whole iPhone App working for the iPad. The next step I needed to take was to convert my Events Calendar to be a splitview. As far as I can tell, I'm don't need to change any of the logic in the two controllers I already have (CalendarViewController and CalendarDetailViewController).
That being said, what is the best way to make them work on a splitview? Is it possible to have the splitview use these two controllers (since a splitview has two controllers by default, a TableViewController and a ViewController)? Would I then need to create another appDelegate or something to pass all the right information back to the MainWindow.xib? Or am I going to need to create a new SplitViewController? and if so, how would I then combine all the logic from my two Calendar Controllers?
Any help would be greatly appreciated!!
Assuming you are using StoryBoard: drag a SplitViewController into the iPad StoryBoard. Also be sure your two desired UIViewControllers are in there. Control-click on the SplitViewController and drag over to each UIViewController and select you how want it set.
I know it's a bit late to answer this question but if someone needs...
You donĀ“t need another appDelegate, you just need to check (in appDelegate) whether your device is an iPad, and then set an array of view Controllers with the MasterVC and the DetailVC. Otherwise you will set your rootViewController as you are doing now in the iPhone app.
It would be something similar to that:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[...]
YourMasterVC *mvc =
[[YourMasterVC alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *masterNav =
[[UINavigationController alloc] initWithRootViewController:mvc];
YourDetailVC *dvc = [[YourDetailVC alloc] init];
cvc.detailViewController = dvc;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// On iPad
UINavigationController *detailNav =
[[UINavigationController alloc] initWithRootViewController:dvc];
UISplitViewController *svc = [[UISplitViewController alloc] init];
svc.delegate = wvc;
svc.viewControllers = #[masterNav, detailNav];
self.window.rootViewController = svc;
} else {
// On iPhone
self.window.rootViewController = masterNav;
}
[...]
}

iOS equivalent to Android Fragments/Layouts

In Android you can use Fragments to develop only one app targeted to phones and tables, so you can have different UI. You can even use only Layouts and have some condition on the code to run tablet or phone logic.
I need to develop an app for iPhone and iPad and I wonder if there is something similar for implementing different UIs and slighty different behavior. In my case the iPhone app would use tabs at the bottom of the screen, but the iPad one should use the menu on the left side.
Yes you can use Different UI for iPhone and iPad.
Create Two XIB files and when showing them on the screen use this condition to initiate the XIB
UIViewController *viewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil] autorelease];
} else {
viewController = [[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil] autorelease];
}
[self.navigationController pushViewController:viewController animated:YES];
UIViewController and XIB, respectively.
Also see Creating a Universal App.

Loading xib dynamically but wrong one displaying

I have an universal app that I am trying to share a viewController code with. I have this:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
AboutController *screen = [[AboutController alloc] initWithNibName:#"iPhoneAboutController" bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
}
else
{
AboutController *screen = [[AboutController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
}
Although this is loading, and when I step through the code, it does hit the xib for the iPhone but it seems to always be loading the iPad version. I know this because in the xib file for the iPhone, I have manually added different background images and it never shows. In the iPhone simulator it shows the iPad version where it is off screen.
Also, if I step through the code in the controller, it does show that the load is the iPhone yet display is all iPad objects. In the iPhone xib, I do have the Files Owner set to the AboutController.
This is the first time I am attempting to "share code". I know I can just create separate class files with the same code but this seems senseless. Any help is greatly appreciated.
Geo...
For starters: make sure you don't override nib initialization in your AboutController.
If not, try cleaning your project (also delete your app's folders in ~/Library/Developer/Xcode/DerivedData). Also uninstall the app from device and then rebuild.

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.