你如何在 Swift 中呈现来自 Xib 的 VC?
How do you present a VC from Xib in Swift?
我正在尝试从 Xib
文件中呈现 VC
,但结果是
Fatal error: Unexpectedly found nil while unwrapping an Optional value
@IBAction func viewCartBtnTapped(_ sender: Any) {
let cart = storyboard?.instantiateViewController(withIdentifier: "CartVC") as? CartVC
present(cart!, animated: true, completion: nil)
}
试试下面的代码,YourStoryBoradName 应该是不带“.storyboard”扩展名的故事板名称:
let storyBoard : UIStoryboard = UIStoryboard(name: "YourStoryBoradName", bundle:nil)
let viewController = storyBoard.instantiateViewController(withIdentifier: "CartVC")as! CartVC
self.present(viewController, animated: true, completion: nil)
我正在尝试从 Xib
文件中呈现 VC
,但结果是
Fatal error: Unexpectedly found nil while unwrapping an Optional value
@IBAction func viewCartBtnTapped(_ sender: Any) {
let cart = storyboard?.instantiateViewController(withIdentifier: "CartVC") as? CartVC
present(cart!, animated: true, completion: nil)
}
试试下面的代码,YourStoryBoradName 应该是不带“.storyboard”扩展名的故事板名称:
let storyBoard : UIStoryboard = UIStoryboard(name: "YourStoryBoradName", bundle:nil)
let viewController = storyBoard.instantiateViewController(withIdentifier: "CartVC")as! CartVC
self.present(viewController, animated: true, completion: nil)