Reputation: 183
I'm trying to implement a refresh button in navigationBar, so when the button is clicked I need to reload the tableView, I have this code, but its not working, for sure the func is called because I put a println inside, Im also declare the reload on ViewDidAppear, but nothing happens :
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()
}
}
Any suggestions? Thanks.
Upvotes: 0
Views: 290
Reputation: 2097
Instead of calling tableView.reloadData()
, it looks like PFQueryTableViewController
has a method called loadObjects()
. Try calling that instead.
Upvotes: 1