How to set root view controller

后端 未结 4 634
长发绾君心
长发绾君心 2021-02-07 10:15

I set up an empty app with only an app delegate class, then subclassed a view controller class to create a xib to layout the app and make connections.

But when I tried

相关标签:
4条回答
  • 2021-02-07 10:28

    You need to set 2 things for that..

    1. in AppDelegate.m file: _applicationDidFinishLaunchingWithOptions_

      self.window.rootViewController = self.viewController;

    2. in application.m

      retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

    0 讨论(0)
  • 2021-02-07 10:32

    Since you're apparently using .xib files, load your view controller and the set the window's rootViewController property to your view controller in -application:didFinishLaunchingWithOptions:.

    0 讨论(0)
  • 2021-02-07 10:44

    in AppDelegate.m

    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    
    
    
        UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:];
    
        self.window.rootViewController = viewController;//making a view to root view
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    
    0 讨论(0)
  • 2021-02-07 10:50

    Applications are expected to have a root view controller

    Replace in AppDelegate

     [window addSubview:[someController view]];
    

    to

     [self.window setRootViewController:someController];
    
    0 讨论(0)
提交回复
热议问题