Instantiate and Present a viewController in Swift

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

    This answer was last revised for Swift 5.2 and iOS 13.4 SDK.


    It's all a matter of new syntax and slightly revised APIs. The underlying functionality of UIKit hasn't changed. This is true for a vast majority of iOS SDK frameworks.

    let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "myVCID")
    self.present(vc, animated: true)
    

    If you're having problems with init(coder:), please refer to EridB's answer.

提交回复
热议问题