Converting an iPhone app to Universal in Xcode 4 - iphone

I could use a little clarity here.
I've opened a project that is a completed iPhone app. Then selected the target, selected "Universal" from the Summary/Devices dropdown, and followed the prompt to "Make a Universal App."
Xcode created a folder "iPad" with the file "MainWindow-iPad.xib" within.
Fine.
Now I duplicated all of my other nib files, and added "-iPad" after their name. I.e. "MySpecialVC.xib" was duped and renamed "MySpecialVC-iPad.xib." The thought was that Xcode knows some zoodoo about finding the correct xib for the device.
Not so fine.
Then I read that the "-iPad" had to be "~ipad" (tilde, then lower-case ipad). This solved the problem with some of the xibs, but not all of them.
Dang if I can't figure this out. Is there a RIGHT way to do this?

When I create a new universal project, I get this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
So it's clear the code is explicitly choosing a xib file. Is this not the case for your project?

Related

GUI not proper after duplicated xib for ipad?

I have duplicated iphone xib into iPad xib by duplicating the target, now my most of the xibs are converted properly into iPad size, however some xibs still showing as iphone size only. Apart from that most of the GUI functionalities like Alert View showing, Action sheet are all not as per iPad. What changes do I need to make to work perfectly for iPad.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Edit: GUI ISSUE I have given two option in that Action sheet YES and NO, only YES showing NO is hiding somewhere..
thanks
Problem is not with conversion, Its with the usage of Action sheet in ipad. Check how to use Action sheet in ipad,
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html
it may fix your problem
You aren't loading the correct NIB when the app starts. This is the code provided by the Xcode "Single View" App Template, which detects the device and loads the appropriate NIB file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[MainViewController alloc] initWithNibName:#"MainViewController_iPhone" bundle:nil];
} else {
self.viewController = [[MainViewController alloc] initWithNibName:#"MainViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

White screen for ios Project

I just tried to duplicate an existing iOS project. After copying over all the files, and fixing all the errors, I am simply getting a white screen when the app launches. Any ideas? I do not have any MainWindow.xib files, nor are any xib files mentioned in my plist. Here is my launch code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MainMenuViewController *mainMenu = [[MainMenuViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenu];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
When i set a breakpoint in MainMenuViewController's viewDidLoad method, it hits it just fine. Any ideas?
I just figured it out... all of my .xib files were missing from the "Copy Bundle Resources" section of Build Phases.
MainMenuViewController *mainMenu = [[MainMenuViewController alloc] init];
Had you set view's frame of mainMenu?

Main AppDelegate not getting called in universal application for iphone

I am working on xcode project intended to make a universal app.With the window based application template i got 3 AppDelegate Methods.2 for both ipad and iphone each and 1 Main AppDelegate method.When i run it for ipad ,the Main AppDelegate method is being called but when i run it for iphone environment ,the Main AppDelegate is not getting called.So how to get the controller to Main Appdelegate method while running it for Iphone environment..??
Here is description..
I have 3 appdelegate methods ,viz.prjOUMAppDelegate(main appdelegate),prjOUMAppDelegate_iPhone(for iphone),prjOUMAppDelegate_iPad(for ipad)..
I have some common methods like creating folders and moving files written in prjOUMAppDelegate(main appdelegate)method.I want it to run everytime irrespective of device ,so that i can get my folders created and some files to be moved.Its working fine when i run it for ipad(i.e creating folders and moving files ) but when i change the environment to iphone ,the prjOUMAppDelegate(main appdelegate) method is not getting called..so i dont know where iam getting wrong..
Ok, Your question is really a confusing one. I think you are looking for something like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = //Initialize the ViewController for iPhone environment
}
else {
self.viewController = //Initialize the ViewController for iPad environment
}
self.navigationController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
If this is not the answer you are looking for then please update your question with some code.

"Application windows are expected to have a root view controller at the end of application launch" error only on iPad

I am trying to convert my iPhone only application to a Universal application. I switched the devices to Universal and let Xcode do it's thing making a MainWindow-iPad.xib for me, and now when I run the app in the iPhone simulator it works fine, but when I run it in the iPad simulator I get a white screen and the Application windows are expected to have a root view controller at the end of application launch error. I have read some other posts about this same problem but none of them are just limited to one device.
Here is my application:didFinishLaunchWithOptions: method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* some dropbox setup stuff */
// INIT VIEW AND CORE DATA
RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
// Handle the error.
}
rootViewController.managedObjectContext = context;
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;
[_window addSubview:[_navigationController view]];
[_window makeKeyAndVisible];
[rootViewController release];
[aNavigationController release];
return YES;
}
EDIT: I just have one root view controller that is sized for iPhone called RootViewController. But it should still load in shouldn't it? Or if it shouldn't how do I create one for iPad?
Change the following line:
[_window addSubview:[_navigationController view]];
to:
_window.rootViewController = _navigationController;
or, if you need iOS 3 compatibility:
if ([_window respondsToSelector:#selector(setRootViewController:)]) {
_window.rootViewController = _navigationController;
} else {
[_window addSubview:_navigationController.view];
}
You need to create a RootViewController with the xib file for iPad, otherwise you will get this error. Below are the template code provided by Xcode for universal app. If you debug the app in iPad simulator and point the debugger to run create the view controller with iPhone xib file, you will see the exact error.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[SYKViewController alloc] initWithNibName:#"SYKViewController_iPhone" bundle:nil];
} else {
self.viewController = [[SYKViewController alloc] initWithNibName:#"SYKViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
In iOS 4 and later, UIWindow has the settable property rootViewController. This is the UINavigationController that pushes the UIViewController displayed on application launch. In Xcode IB, selecting Initial Scene: Is initial view controller for the UINavigationController sets everything up with no code required.
From the generated MainWindow-iPad.xib, in Interface Builder, add a View Controller object in IB, as well as an Object underneath the View. For the object, set it's class to AppDelegate, for the View Controller, set the class to ViewController (i the Identity Inspector) and specify the nib name in the Attributes Inspector. You can look at the MainWindow.nib for the device you were converting from to see the differences.
Edit: I forgot to mention some important steps. You will also need to set the File's Owner class to "UIApplication" in IB, and set the referencing outlets appropriately for the App Delegate and View Controller. Again, in IB, it's easiest to look at the Connections Inspector for the MainWindow nib you had and emulate it. If you have another nib specific to the iPad, other than MainWindow-iPad.nib (i.e. ViewController-iPad.nib), be sure to select it's File's Owner and point it to the view and set it's class appropriately too.
I tried your suggestions but none of them worked for me, sorry. :/ I ended up just making the view manually in code without interface builder:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// Setup view for iPad
} else
// Setup view for iPhone and iPod Touch
}
which I thought would be a lot harder than it actually was.
Note that if you use this method you can still hook up everything in interface builder and just change the frame of objects in these blocks if you are going to have the same objects on both iPhone and iPad.

iPhone switch screen in xcode 4.2

I am new to iPhone app. I was told not to use Xcode storyboard for the app to be compatible with iOS4.3 and under.
Right now, I have 2 pages showing using a tabcontroller, however I am trying to add a page that loads up first when the program is started (i.e. a Login page), after authenticated the user will land on the first page of the 2 tabs.
What would I need to do? Should I create a MainWindow.xib file?
Thanks!
James
You have (at least) two solutions. You can :
*Create the window the the didFinishLaunching function in your AppDelegate, with something like that:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RootViewController *controller = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
self.navigationController.delegate = controller;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
*or you can create the MainWindow.xib file with the AppDelegate and the window, and tell your app use this nib when launched. To do that :
In the .plist, enter MainWindow for the "Main nib file base name" characteristic.