need help understanding my error on my first iPhone app [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
applications expected to have a root view controller console
I'm trying to build the first app by following a book step by step but I guess I'm making a mistake.
it's a simple view app with just a logo nd a label and then I click build and run and it says "build succeded", but when ios simulator pop up the app is still blank, even if I go back home and ropen the app nothing change.
I see on the debug window this statement:
2012-10-26 04:07:03.376 welcome[1219:c07] Application windows are expected to have a root view controller at the end of application launch
AS far as I understand my app lacks of a root view controller but how can I implement it?

You specify the root view controller in your appDelegate class. It should look something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
The important lines that you need to add are:
self.viewController = [[[ViewController alloc] initWithNibName:#"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
And under initWithNibName you put the name of the xib you created your interface in.
Note: Only add autorelease if your project isn't using ARC.

Related

iPad crashes when running iPhone app in compatibility mode

I just had one of my apps reviewed, and I never knew this but apparently an iPhone specific app must also be able to run on the iPad in compatibility mode... I never knew this, and it doesn't really make sense.
Anyways, my app is crashing when calling didFinishLaunchingWithOptions
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *rootViewController;
rootViewController = [[[WPViewController alloc] initWithNibName:#"WPViewController_iPhone" bundle:nil] autorelease];
self.viewController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
self.viewController.navigationBar.barStyle = UIBarStyleBlack;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Using NSLog, I can see that it crashes when I call [self.window makeKeyAndVisible]; And also, if I remove that line of code and run it in the iPad simulator, it does not crash, but obviously shows a blank screen. The app runs fine on the iPhone simulator
Any ideas? or places to start looking?

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.

how to create a menu based ios application in xcode 4.2

I have no idea how to set up a menu based project in xcode 4.2.
Basically, the menu has 4 buttons in it each go to their own Navigation Controlled tableviews, but I'm not sure where to start with xcode 4.2.
In my previous application I have a main window that has the navigation controller in that, then there is a root view which sets up the 4 buttons and from there the tableview view controllers just get loaded into the navigation controller.
With xcode 4.2 I cannot seem to set the delegate of the main window, so I cannot figure this out.
So I am hoping someone understands what I am trying to do and can help me out or send me a example or tutorial or something. Thanks, any help would be greatly appreciated.
Here is how I setup my navigation controller and root view in the AppDelegate file. From there you can just add the buttons and so on just as before. If you mean to do it with the storyboard, it will be much easier. Let me know if I misunderstood the question though:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self managedObjectModel];
[self managedObjectContext];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
RootViewController *controller = [[RootViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window setRootViewController:navigation];
[controller release];
[navigation release];
[self.window makeKeyAndVisible];
return YES;
}
You'll be fine with one UINavigationController. In your view with the 4 menu buttons just hide the UINavigationController.
Hide / Show UINavigationController

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.

Converting an iPhone app to Universal in Xcode 4

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?