0

After switching to Xcode 4, I thought I would be able to build and run my application exactly like I could in Xcode 3.

Turns out I can't.

Xcode 4 has a funny way of never showing the app's view controller, which is strange.

I can tell Apple's going to eventually force us to switch, which will result in my app being inoperable.

It gets to application:didFinishLaunchingWithOptions: without any errors, before hanging. Eventually the application crashes on the device - but stays on Default.png forever in the simulator.

I thought I could go and edit the application:didFinishLaunchingWithOptions: method the instantiate an instance of the view controller itself and add it to the window - only to reveal that didn't work either.

After numerous failed attempts at this - creating separate UIWindows for the main view controller - I decided the add it to a navigation controller.

Luck then struck me - but only in the simplest of forms. I looked in the log and see that applicationDidBecomeActive: had been called.

But, as usual, no such luck with any sort of view being displayed.

I then decided to see if I could add a UIView with a blue background color and a few UI elements (buttons, labels, etc...) to the window and see if that would work.

Funnily enough it did.

But why not for the main view controller? Not once in Xcode 4 have I successfully had it run my app (even opening it after it has been built fails). I've tried changing the compiler to the same as in Xcode 3, no luck.

I am honestly really confused as to why the application's view controller won't display.

For anyone who wants to give it an attempt as to why it isn't working that would be gratefully appreciated.

Here's the code for the AppDelegate, if you need the code for the view controller I can paste it here, however it's over 2000 lines.

Anyway, here's the .m file:

#import "DocumentationAppDelegate.h"
#import "DocumentationViewController.h"

@implementation DocumentationAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize navigationController;

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"In method %@, which is in class %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class]));
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"In method %@, which is in class %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class]));

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSLog(@"In method %@, which is in class %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class]));

    DocumentationViewController *vc = [[DocumentationViewController alloc] init];

    UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vc];
    controller.navigationBarHidden = YES;

    UIWindow *win = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [win addSubview:controller.view];
    [win makeKeyAndVisible];

    return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application {

}


- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

and the .h

#import <UIKit/UIKit.h>

@class DocumentationViewController;

@interface DocumentationAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    DocumentationViewController *viewController;
    UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet DocumentationViewController *viewController;

@end

If any one could help me here it would be tremendously appreciated.

Jack Greenhill
  • 10,240
  • 12
  • 38
  • 70

1 Answers1

0

Your app delegate already has the properties window, viewController and navigationController. So you can have the application:didFinishLaunchingWithOptions: method like this,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    viewController = [[DocumentationViewController alloc] init];
    navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    navigationController.navigationBarHidden = YES;

    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}
EmptyStack
  • 51,274
  • 23
  • 147
  • 178