我有一个问题,我想从 firstVC 调用一种方法到 seccondVC 我尝试使用这样的代码:
let storyboard: UIStoryboard = UIStoryboard.init(name: "MainScreenVC", bundle: nil)
let firstViewController: MainScreenVC = storyboard.instantiateViewController(withIdentifier: "MainScreenVC") as! MainScreenVC
firstViewController.automatingFullFill()
但是我马上收到错误,有什么不对?
我的错误:
'无法在捆绑NSBundle中找到名为'MainScreenVC'的故事板
答案 0 :(得分:2)
如果要为每个视图控制器提供单独的故事板,则必须提供故事板名称和视图控制器名称。
let storyboard: UIStoryboard = UIStoryboard.init(name: "give storyboard name here ", bundle: nil)
let firstViewController: MainScreenVC = storyboard.instantiateViewController(withIdentifier: "viewcontrollername here") as! MainScreenVC
firstViewController.automatingFullFill()
(OR) 您也可以这样称呼它
let mainScreenVC = UIStoryboard.init(name: "give Storyboard name here", bundle: nil).instantiateViewController(withIdentifier: "viewcontroller") as! MainScreenVC