Instantiate and Present a viewController in Swift

前端 未结 16 1752
难免孤独
难免孤独 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:29

    No matter what I tried, it just wouldn't work for me - no errors, but no new view controller on my screen either. Don't know why, but wrapping it in timeout function finally made it work:

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.0) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "TabletViewController")
        self.present(controller, animated: true, completion: nil)
    }
    

提交回复
热议问题