【问题标题】:How can use delegate for show ViewController in the MainStoryboard from vc in other Storyboard?如何在其他 Storyboard 中的 vc 中使用委托在 MainStoryboard 中显示 ViewController?
【发布时间】:2019-03-31 02:05:56
【问题描述】:

我有 2 个故事板:MainStoryboardLoginStoryboard。我想在 2 故事板中使用 LoginViewController 中的委托。当我点击LoginViewController 中的登录按钮时,我想调用代理并在main.storyboard 中显示一个名为ProfileViewController 的特定UIViewController

这是我的课:

LoginDelegate.swift -> 代表

LoginViewController.swift -> 这是 LoginStoryboard 中的初始 vc

HomeViewController.swift -> 是 MainStoryboard 中的初始 vc

ProfileViewController.swift -> 这是 MainStoryBoard 中的一个 vc,我接下来要显示我点击登录按钮

你能帮帮我吗?

【问题讨论】:

  • 这很有趣,但是如果两个视图控制器位于不同的故事板中,我该如何设置 segue 标识符?
  • 解释更多你真正想做的事情,所以我可以帮忙

标签: ios swift uiviewcontroller delegates storyboard


【解决方案1】:

您必须在您的Login.storyboard 中添加一个Storyboard Reference,如下所示:

然后,参考你的main.storyboard

【讨论】:

    【解决方案2】:

    您必须在登录按钮操作中调用此行:

    let kMainStoryBoard = UIStoryboard.init(name: "Main", bundle: nil)
    if let profileVC = kMainStoryBoard.instantiateViewController(withIdentifier: "your profile VC storyboard identifier") as? ProfileViewController {
            let navigation = UINavigationController(rootViewController: profileVC)
            self.present(navigation, animated: true, completion: nil)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多