【问题标题】:Present view controller from another storyboard从另一个故事板呈现视图控制器
【发布时间】:2018-12-12 22:33:51
【问题描述】:

index.swift

func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
    print("Receive")
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let goController = mainStoryboard.instantiateViewController(withIdentifier: "call") as! call
    self.present(goController, animated: true)
}

如果我在index.swift 并收到会话,请为我打印Receive 并转到call.swift

但如果在加载index.swift 后我转到page.swift,如果接收会话,则打印Receive 但不要转到call.swift 并继续page.swift

如果我在present 之后的任何地方,请转到call.swift

【问题讨论】:

  • 很难准确地理解你在这里的要求,你能详细说明一下吗?您只是想以编程方式从与当前正在查看的 VC 不同的故事板中打开 VC?
  • @JustinMiller,是的。我在索引 VC 中编写代码,但我不在索引 VC 中。如果我调用索引代码,不要去另一个 VC

标签: ios swift uiviewcontroller uistoryboard


【解决方案1】:
  • 打开您的第一个 Storyboard 并创建 Storyboard Reference

  • 在“Storyboard”属性中输入第二个 Storyboard 的名称,在新创建的引用的“Reference ID”属性中输入目标 ViewController 的引用 ID。 (Reference ID 相当于目标 ViewController 的 Storyboard ID)

  • 创建一个从源 ViewController 到新创建的 Storyboard Reference 的 segue。确保 segue 有一个标识符。

  • 在你的代码中像这样执行segue

func didReceiveNewSession(_ session: QBRTCSession, userInfo: [String : String]? = nil) {
    print("Receive")
    self.performSegue(withIdentifier: "mySegue", sender: self)
}

感谢https://stackoverflow.com/a/33753164/7990095

【讨论】:

  • 你的意思是 Xcode 项目文件?很抱歉,由于版权原因,我无法发送该项目。只要问您是否无法按照这些步骤操作,我会尝试进一步解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 2012-02-13
  • 1970-01-01
  • 2019-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多