【问题标题】:Not able to show View Container in Container View in iOS无法在 iOS 的容器视图中显示视图容器
【发布时间】:2018-04-13 14:03:56
【问题描述】:

我正在参考教程here

我有一个包含容器视图的视图控制器。在这个容器视图上,我添加了自定义 Segue,即 FirstViewController。这意味着当我打开 View Controller 时,它默认显示 FirstViewController。在 FirstViewController 上,我有一个按钮。通过单击此按钮,我想显示 SecondViewController 但我无法实现这一目标。我还在按钮单击上添加了打印命令,它在控制台上打印,而不是切换到另一个视图。请帮忙。

我在 FirstViewController 中创建了一个委托和一个通过 ViewController 引用的函数。

FirstViewController.swift 的代码

  protocol FirstViewDelegate: class {
    func sendToSecondViewController()

 }

   class FirstViewController: UIViewController {

     weak var delegate: FirstViewDelegate? = nil

     @IBAction func goToSecond(_ sender: UIButton) {

    print("test1")
     delegate?.sendToSecondViewController()

       }


    }

ViewController.swift 的代码

      extension ViewController: FirstViewDelegate{

func sendToSecondViewController() {
    container.segueIdentifierReceivedFromParent("second")
}

     }

还有 main.storyboard

【问题讨论】:

  • 简单地说,你想换一个视图控制器吗?
  • 是的,但是想在同一个容器视图中打开它

标签: ios swift swift3 uiviewcontroller


【解决方案1】:

您似乎没有在 ViewController 中设置 FirstViewController 的委托。比如:

<object of FirstViewController>.delegate = self (Inside ViewController)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 2017-11-20
    • 2016-11-29
    • 2013-04-08
    • 2014-02-16
    相关资源
    最近更新 更多