Instantiate and Present a viewController in Swift

前端 未结 16 1804
难免孤独
难免孤独 2020-11-22 13:04

Issue

I started taking a look of the new Swift on Xcode 6, and I tried some demo projects and tutorials. Now I am stuck at:

16条回答
  •  半阙折子戏
    2020-11-22 13:12

    This link has both the implementations:

    Swift:

    let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController") as UIViewController
    self.presentViewController(viewController, animated: false, completion: nil)
    

    Objective C

    UIViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
    

    This link has code for initiating viewcontroller in the same storyboard

    /*
     Helper to Switch the View based on StoryBoard
     @param StoryBoard ID  as String
    */
    func switchToViewController(identifier: String) {
        let viewController = self.storyboard?.instantiateViewControllerWithIdentifier(identifier) as! UIViewController
        self.navigationController?.setViewControllers([viewController], animated: false)
    
    }
    

提交回复
热议问题