Instantiating a Swift ViewController in an Objective-C project

旧时模样 提交于 2019-12-11 12:11:29

问题


I've imported a Swift UIViewController in an Objective-C-based project and I've followed

  • Apple's guide to using Swift Classes in Objective-C

and

  • This useful step-by-step Swift integration for Xcode Objc-based projects

My project doesn't crash, but I can't get a view to load. I'm attempting to instantiate a viewController, but it shows up as a white blank screen:

UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"mySwiftVC"];

I put a breakpoint in immediately after the prior line and po rootViewController gives a memory address.

I threw a println in the viewDidLoad of MySwiftVC, but nothing comes up. All the lights "are on", but nothing displays/executes. Any ideas where to look for resolution?

Here's the method where the prior line was called:

- (void)checkDisclaimer {
    UIStoryboard *storyboard = self.window.rootViewController.storyboard;

    if ([[[NSUserDefaults standardUserDefaults]valueForKey:@"disclaimerAcknowledged"]boolValue] == NO) {
        // set to instantiate disclaimer VC
        UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"disclaimer"];
        self.window.rootViewController = rootViewController;
        NSLog(@"Disclaimer IS NOT acknowledged");
    } else {
// this is the line that's working from a memory standpoint, but nothing happens
        UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"launchScreen"];
        self.window.rootViewController = rootViewController;
        NSLog(@"Disclaimer IS acknowledged");
    }
    [self.window makeKeyAndVisible];

}

来源:https://stackoverflow.com/questions/31590419/instantiating-a-swift-viewcontroller-in-an-objective-c-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!