gpt4 book ai didi

uitableview - 我无法让我的 UITableView 快速重新加载数据

转载 作者:行者123 更新时间:2023-11-28 05:30:57 25 4
gpt4 key购买 nike

我正在使用 UITableView 列出多个设置,并在单元格标题中显示该设置的状态。选择单元格后,它会转到我更改设置的另一个 View 。我使用导航控件返回到 UITableView 但是我无法更新表格

class OptionTable: UITableViewController{

var table : [[String:AnyObject]] = []
var data = NSMutableDictionary()

func dataFilePath() -> String {
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDirectory = paths[0] as NSString
return documentsDirectory.stringByAppendingPathComponent("data.plist") as String
}

override func viewDidLoad() {
super.viewDidLoad()
data = NSMutableDictionary(contentsOfFile: self.dataFilePath())!
table = data["table"] as [[String:AnyObject]]
}
override func viewWillAppear(animated: Bool) {

self.tableView.reloadData()

}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return table.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var rowTable : Dictionary = table[indexPath.row]
cell.textLabel?.text = rowTable["Title"] as? String

return cell
}
}

数据正在保存在 plist 中,只是在我打开 UITableView 备份时没有重新加载。当我返回另一个页面然后再次转发到 UITableView 时,表格确实会重新加载。

为什么 self.tableView.reloadData() 不起作用???任何帮助将不胜感激。

最佳答案

您可能正在将 保存到 plist,但是 viewDidAppear 在刷新 tableView 之前没有加载它。

将 plist 的加载移动到 viewDidAppear 中。

关于uitableview - 我无法让我的 UITableView 快速重新加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28499569/

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