gpt4 book ai didi

ios - 无法将数据从一个 View Controller 推送到 TableView Controller

转载 作者:行者123 更新时间:2023-11-30 12:52:01 25 4
gpt4 key购买 nike

我在做项目时遇到了一个奇怪的问题。 (请耐心等待,我是 Swift 初学者。)

这就是我到目前为止的 Storyboard的样子。 On the left is my regular view controller, and on the right is the TableViewController. the transition inbetween has a specific ID.

**This is the first View Controller.**

class TestsMenuViewController: UIViewController {
var tests = [Test]()
var testTableViewController : TestsTableViewController?


override func viewDidLoad() {
self.tests = DataModel().patientData
//this just populates the array with some data.
super.viewDidLoad()
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "testTableTransition" {
testTableViewController = segue.destination as? TestsTableViewController
testTableViewController?.tests = self.tests
print(testTableViewController?.tests[0].testDescription)
//somehow this is an empty array
}
}

不知何故,测试数组没有传递到下一个 Controller :(我做错了什么?

最佳答案

您可以将数据保存为 NSUserDefaults 并在需要时将保存的数据调用到 View

关于ios - 无法将数据从一个 View Controller 推送到 TableView Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40850681/

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