swift - 不更新帖子 Parse Swift

标签 swift parse-platform

在我的解析数据库中,我在应用程序中创建了一些数据,但是当我转到显示帖子的 TableViewController 时,它由于某种原因而没有更新。这是我的代码(如果需要帮助解决此问题,我可以提供有关解析数据库的更多信息):

import UIKit
import Parse
import ParseUI

class PostsTableViewController: PFQueryTableViewController {

    override func queryForTable() -> PFQuery {

        let query = PFQuery(className: "Posts")
        query.cachePolicy = .CacheElseNetwork
        query.orderByDescending("createdAt")
        return query
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {

        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! PostsTableViewCell

        let posterUsernameText = object?.objectForKey("createdBy") as? String
        cell.posterUsername.setTitle("\(posterUsernameText)", forState: .Normal)

        cell.msgTextView.text = object?.objectForKey("text") as? String

        let imageFile = object?.objectForKey("image") as? PFFile
        cell.cellImageView.file = imageFile
        cell.cellImageView?.loadInBackground()

        return cell

    }

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

        if indexPath.row + 1 > self.objects?.count {

            return 44

        }

        let height = super.tableView(tableView, heightForRowAtIndexPath: indexPath)
        return height
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        if indexPath.row + 1 > self.objects?.count {

            self.loadNextPage()
            tableView.deselectRowAtIndexPath(indexPath, animated: true)

        } else {

            self.performSegueWithIdentifier("showDetail", sender: self)

        }
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "showDetail" {



        }

    }

}

编辑:这是我的数据库的照片和我的屏幕的照片: enter image description here

enter image description here

enter image description here

最佳答案

我相信您需要重新加载 PFQueryTableView 的数据,并且可以使用 loadObjects 方法来完成此操作。正如 Parse 文档中提到的,它会清除表格并加载对象的第一页。 (您可以使用 loadNextPage 将下一页对象加载到 TableView 上)这是一个 link PFQueryTableViewController 的文档

关于swift - 不更新帖子 Parse Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34673919/

相关文章:

javascript - 解析 Promise,destroyAll();不工作?

ios - 解析指向对象 EXC_BAD_ACCESS 的指针

swift - 当协议(protocol)具有关联类型时,从常规方法调用协议(protocol)默认实现

Swift - 重置嵌入在选项卡栏中的导航 Controller 中的 vc

Swift 中的 macOS 键盘快捷键

java - 应用在使用解析测试推送通知时崩溃

ios - swift + Parse.com : how to fetch user relation using a join table

swift - 如何点击更改模型的颜色,然后将其改回原来的颜色?

android - OpenGL ES 2.0 Android至IOS Swift 3

ios - 使用 Parse 查询指针属性