Search code examples
iosmainwindow

How to add AppDelegate mainwindow xib in Singleview application


I have SingleView application. Now I want to add a mainwindow to my project.

How can I add the window into my project?

Thanks in advance.


Solution

  • First Add Your LoginViewController as self.window.rootViewController such like

    Add this code in your Appdelegate.h file

    #import <UIKit/UIKit.h>
    #import "AppDelegate.h"
    @interface AppDelegate : NSObject <UIApplicationDelegate> 
    
    {
        UIWindow *window;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    
    @end
    

    Add this code in your Appdelegate.m file (Here i also added UINavigationController too)

      @synthesize window=_window;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    
        LoginViewController *loginViewController = [[LoginViewController alloc] init];
        UINavigationController *loginNVController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
        loginNVController.navigationBarHidden = YES;
        self.window.rootViewController = loginNVController;
    
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

    OR Add Directly

    Check this link for adding window.xib . Check this link