【问题标题】:how can i pass data using dismiss?我如何使用驳回传递数据?
【发布时间】:2021-02-25 16:22:58
【问题描述】:

我有两个 viewControllers A B

我使用 performegue 从 A 到 B 并使用 prepare() 将 A 传递给 B。

segue 类型是 Show。

if segue.identifier == "toWrite"{
            let vc = segue.destination as? WriteViewController
            vc?.diary = Date[Date.count-1]
            vc?.made_content = made_content
            vc?.presentIndex = Date[Date.count-1].presentIndex
            vc?.presentIndex = sendIndex
        }

但是当我从 B 到 A 时, 我想将 B 数据传递给 A

我做不到\

【问题讨论】:

  • 使用 unwind segue,或者使用协议/委托模式在视图控制器 B 和 A 之间进行通信
  • 如何解除segue?我做不到

标签: swift segue viewcontroller


【解决方案1】:

另一种方式是使用非常常见的协议和委托。

我会推荐你​​这个链接,有一个好的开始

https://learnappmaking.com/pass-data-between-view-controllers-swift-how-to/#back-properties

【讨论】:

    【解决方案2】:

    您可以将 A 视图控制器实例传递给 B,并将 B 的更改设置为 A。

    我认为最好的方法是展开 segue 以将数据从 B 传递到 A。

    请参考以下链接,该链接解释了如何使用 unwind segue。

    https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 2015-08-30
      相关资源
      最近更新 更多