【问题标题】:From Container View to go another container view in Swift 3从 Container View 到 Swift 3 中的另一个容器视图
【发布时间】:2023-03-18 03:34:02
【问题描述】:

我试试,http://kodesnippets.com/index.php/2015/08/11/container-view-in-ios/ 教程,我下载了 GitHub 项目,但我没有这样做,

从 First Container 到带有按钮操作的第二个容器视图

我的代码在下面。

我只加了

FirstViewController 里面

 var container: ContainerViewController!

  @IBAction func test(_ sender: UIButton) {


       container!.segueIdentifierReceivedFromParent("second")


    }


    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "container"{

            container = segue.destination as! ContainerViewController


        }
    }

我将按钮操作链接到测试。当我点击它时,它给了我;

致命错误:在展开可选值时意外发现 nil

这一行出错,没有转到第二个视图控制器

container!.segueIdentifierReceivedFromParent("second")

有什么想法吗?下面还有 GitHub 链接。

https://github.com/iaaqib/ContainerView

【问题讨论】:

    标签: ios swift3 containers segue


    【解决方案1】:

    变量容器未设置为指向任何内容。

    【讨论】:

    • 我只添加了该代码并链接了按钮操作。
    • 忽略我之前关于 ctrl 拖动的回复,说的是垃圾。您是否将嵌入式 segue 设置为“容器”?如果不是,prepare() 中的代码将不会设置容器
    【解决方案2】:

    FirstViewController 没有任何 segue,所以 prepare(for segue: UIStoryboardSegue, sender: Any?) 方法没有被调用,这就是容器属性为 nil 的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 2014-08-27
      相关资源
      最近更新 更多