starting ios project without storyboard

前端 未结 9 1241
渐次进展
渐次进展 2021-01-12 23:28

Im having some troubles to start an iOS app using xibs instead of storyboard. The problem is that im getting a black screen and the first view controller is not being called

9条回答
  •  暖寄归人
    2021-01-12 23:57

    I didnt try with XIB, but this thing is working fine here:::

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.viewController = [[ViewController alloc] init];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
        navController.navigationBarHidden = YES;
    
        self.window.rootViewController = navController;
        [self.window makeKeyAndVisible];
        // Override point for customization after application launch.
        return YES;
    }
    

    and in ViewController's viewDidLoad

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self.view setBackgroundColor:[UIColor greenColor]];
        // Do any additional setup after loading the view, typically from a nib.
    }
    

    And the green color comes on the screen.

    Initialize the window before setting the root view controller for the window.

    That's the only problem that i see in you code, as the rootViewController is set to a nil window, and after that you are initializing.

提交回复
热议问题