我正试图在navigationBar中实现一个刷新按钮,所以当单击该按钮时,我需要重新加载tableView,我有这段代码,但它不能工作,因为我把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()
}
}有什么建议吗?谢谢。
发布于 2015-07-27 21:50:41
与调用tableView.reloadData()不同,PFQueryTableViewController似乎有一个名为loadObjects()的方法。试着叫它。
https://stackoverflow.com/questions/31663704
复制相似问题