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

标签 swift uitableview parse-platform

我正在尝试在导航栏中实现刷新按钮,因此当单击按钮时我需要重新加载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/

相关文章:

ios - UITableView 单元格约束问题 - Swift

javascript - 解析 - 为什么 user.getSessionToken() 返回未定义

ios - 使用切换动画隐藏/显示 View

iOS 7 UITextView 链接检测在 UITableView 中崩溃

ios - 在 CoreData 中获取实体导致崩溃

uitableview - UITableViewCell 与 UITableViewCellStyleSubtitle 重叠

ios - 为什么来自 parse.com 的推送只能到达一台设备?

ios - 带有 Parse 数据库的 UICollectionView 上的问题

ios - 向 UISearchBar 添加动态类型

ios - 添加注释时 Mapkit 崩溃