将信息从一个故事板传递到另一个故事板

发布于 2025-02-05 20:13:01 字数 222 浏览 1 评论 0原文

我很难将分数从模型页面传递给我的一个控制器之一。我有一个计数器可以总计分数,但是当我尝试将其添加到另一个故事板上的标签中时,它将原始声明的值为零,而不是更新的版本。

这是计数的函数正在发生的地方,我只是在另一个故事板上激活该功能

I am having trouble passing the score to quiz app from a model page to one of my controllers. I have a counter that totals up the score, however when I try and add it to a label on another storyboard it takes the original declared value of zero rather than the updated version.

This is where the function of counting is taking place and im just activating the function on another storyboard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法回应 2025-02-12 20:13:01

显然,它将为您提供零,因为得分变量没有更新。
将得分从一个视图控制器传递到另一个视图控制器的一种方法是:

  1. 创建一个目标视图控制器中的变量
  2. 从当前控制器
  3. 启动目标视图控制器。将当前分数分配给目标视图控制器的变量,然后再推动或展示。
  4. 在ViewDidload或您要显示的任何地方,都将得分分配给其标签
    这是您可以执行的示例代码:
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "myVCID")
vc.anyVariableYouDeclare = currentScore
self.present(vc, animated: true)

Obviously, it will give you zero because there is no update in score variable.
One way to pass score from one view controller to other view controller is as:

  1. create a variable in destination view controller
  2. Initiate destination view controller from current controller.
  3. Assign current score to destination view controller's variable before pushing or presenting it.
  4. In viewdidload or wherever you want to display it, assign score to its label
    Here is sample code you can do:
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "myVCID")
vc.anyVariableYouDeclare = currentScore
self.present(vc, animated: true)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文