gpt4 book ai didi

swift - tableView重新加载数据+解析

转载 作者:行者123 更新时间:2023-11-30 10:13:23 25 4
gpt4 key购买 nike

我正在尝试在导航栏中实现刷新按钮,因此当单击按钮时我需要重新加载tableView,我有这段代码,但它不起作用,肯定会调用func,因为我在里面放了一个println ,我也在 ViewDidAppear 上声明了重新加载,但没有任何反应:

import UIKit

class CommentsTableViewController: PFQueryTableViewController {
@IBOutlet var tabletView: UITableView!


var object : PFObject?

// Initialise the PFQueryTable tableview
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

}

// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "gameScore")
query.orderByDescending("createdAt")
query.whereKey("ObjectId", equalTo: "XDP1rc8Rmq")

return query
}

override func viewDidLoad() {
super.viewDidLoad()


}

override func viewDidAppear(animated: Bool) {

// Refresh the table to ensure any data changes are displayed
self.tabletView.reloadData()
println("Reloading")
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


//override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
var cell = tableView.dequeueReusableCellWithIdentifier("CommentCellIdentifier") as! CommentsCell!
if cell == nil {
cell = CommentsCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CommentCellIdentifier")
}


if let object = object?["user"] as? String {
cell?.username?.text = object
}


return cell

}

func buttonIconAction(sender:UIButton!)
{
println("Reloading")
self.tableView.reloadData()
}

}

有什么建议吗?谢谢。

最佳答案

看起来 PFQueryTableViewController 有一个名为 loadObjects() 的方法,而不是调用 tableView.reloadData()。尝试调用它。

关于swift - tableView重新加载数据+解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31663704/

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