gpt4 book ai didi

ios - 在没有 segue 的 ViewController 之间发送数据

转载 作者:行者123 更新时间:2023-11-29 02:41:43 24 4
gpt4 key购买 nike

有没有办法在不使用 segues 的情况下在 ViewController 之间发送数据?

具体来说,我在 TabBarViewController 中嵌入了两个 ViewController。一个称为 PlayingCardViewController,另一个称为 HighScoreViewController。我想将一个类 HighScore 从 PlayingCardViewController 传递到 HighScoreViewController。我想在按下 PlayingCardViewController 中的重发按钮后立即从 PlayingCardViewController 传输数据,但我不想转换到 HighScoreViewController,因为这会对玩家造成干扰。

我想过使用 segues 并将 HighScores 保存在一个数组中,并将其传递给 PlayingCardViewController 连接到的所有 VC,但我意识到这似乎过于复杂,并且必须有一种更简单的方法来在重发时传递数据按钮。

一些相关链接 Passing Data between View Controllers

最佳答案

我只想用要点来做到这一点:

  • 您可以实现自定义标签栏 Controller (您自己的 UITabBarController 子类),并使用它代替基本的 UITabBarController
  • 您的 PlayingCardViewController 可以有自己的委托(delegate)协议(protocol)/属性。
  • 委托(delegate)协议(protocol)可以定义类似playingCardVC:didSetHighScore:的方法。
  • 您的标签栏 Controller 将是 PlayingCardViewController 的委托(delegate)。
  • 标签栏 Controller 可以保留对 HighScoreViewController 的引用。
  • 当您的标签栏 Controller 获取 playingCardVC:didSetHighScore: 时,它可以将您想要的任何内容传递给您的 HighScoreViewController

关于ios - 在没有 segue 的 ViewController 之间发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25689907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com