iphoneuitabbarcontrolleruiapplicationdelegateios5.1uiwindow

iOS: Window object is nil


I had an app delegate and I needed to add custom tab bar controller to override UITabbarController. I have created Window user interface, reference Window to Appdelegate's Window object. made File's owner to UIApplication, added NSObject and changed identity class to my delegate, added UITabbarController and changed identity class to my custom tabbar controller. Now I see very unusual that Window object in didFinishLaunchingWithOptions is coming nil so I don't see anything on the screen. Also my custom tabbar controller object is nil! Following is my new Window structure and main.m. Could anyone please tell me where am I doing wrong? Thanks.

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}


Appdelegate.h

#import <UIKit/UIKit.h>
#import "CustomTabBarController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) IBOutlet UIWindow *window;

@property (strong, nonatomic) IBOutlet CustomTabBarController *tabBarController;

@end

Appdelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if(_window == nil) // This is true for self.Window as well!
        NSLog(@"nil");
    if(_tabBarController.view == nil)
        NSLog(@"nil");
    [self.window addSubview:self.tabBarController.view];
    [self.window makeKeyAndVisible];
    return YES;
}  

enter image description here


Solution

  • I got this resolved...Two things were missing.

    1. File's owner inspector, reference outlets delegate to AppDelegate.
    2. In project's target settings, set main interface to newly created Window.