代码之家  ›  专栏  ›  技术社区  ›  Best Moments

iOS如何从另一个视图控制器swift调用func

  •  1
  • Best Moments  · 技术社区  · 6 年前

    我有一个问题,我想从 第一个VC 秒VC 我尝试使用这样的代码:

    let storyboard: UIStoryboard = UIStoryboard.init(name: "MainScreenVC", bundle: nil)
    let firstViewController: MainScreenVC = storyboard.instantiateViewController(withIdentifier: "MainScreenVC") as! MainScreenVC
    firstViewController.automatingFullFill()
    

    但我一收到错误,怎么了?

    我的错误:

    “在bundle nsbundle中找不到名为”mainscreenvc“的故事板”

    1 回复  |  直到 6 年前
        1
  •  2
  •   Malleswari    6 年前

    如果要为每个viewcontroller单独制作情节提要,则必须提供情节提要名称和viewcontroller名称。

    let storyboard: UIStoryboard = UIStoryboard.init(name: "give storyboard name here ", bundle: nil)
    let firstViewController: MainScreenVC = storyboard.instantiateViewController(withIdentifier: "viewcontrollername here") as! MainScreenVC
    firstViewController.automatingFullFill()
    

    (或) 你也可以这样称呼它

     let mainScreenVC = UIStoryboard.init(name: "give Storyboard name here", bundle: nil).instantiateViewController(withIdentifier: "viewcontroller") as! MainScreenVC