swift - 重新加载 PFTableViewCell 中的单行 - 返回 PFTableViewCell 没有 cellForRowMethod

标签 swift parse-platform tableview uitableview cell-formatting

好的,所以我一直在尝试为我正在开发的应用程序制作一个赞按钮,并且我正在使用解析作为后端。到目前为止,我可以在解析中更新点赞按钮,但是,我只能重新加载整个表格 View ,而不仅仅是单个单元格。重新加载整个 tableview 有时会导致 tableview 上下移动,我相信是因为不同大小的单元格。

      @IBAction func topButton(sender: UIButton) {
    let uuid = UIDevice.currentDevice().identifierForVendor.UUIDString
    let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
    let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
    let object = objectAtIndexPath(hitIndex)

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: hitIndex!) as TableViewCell
    //var indexOfCell:NSIndexPath

    //indexOfCell = hitIndex!
    if object.valueForKey("likedBy") != nil {

        var UUIDarray = object.valueForKey("likedBy")? as NSArray
        var uuidArray:[String] = UUIDarray as [String]

        if !isStringPresentInArray(uuidArray, str: uuid) {

            object.addObject(uuid, forKey: "likedBy")
            object.incrementKey("count")
            object.saveInBackground()                
            //self.tableView.reloadData()
        }
    }
}

我已经用正确的 indexPath 尝试了 cellForRow,它总是返回 PFTableViewCell 不包含 cellForRowAtIndexPath 方法。我在一个论坛上读到有人能够创建自定义方法来重新加载单元格,Parse 的文档使用 PAPCache 来执行点赞按钮。幸运的是,Parse 页面上的点赞按钮的文档在 Obj-C 中,我已经用 Swift 编写了我的应用程序。如果您想查看,这里是页面的链接:https://www.parse.com/tutorials/anypic#like .第 6.1 节。

TD;LR 我不确定如何更新单元格,以便在没有 cellForRowAtIndexPath 方法的情况下不会重新加载整个 tableview。也许自定义方法?也许是 PAPCache 方法?

已解决

  if object.valueForKey("likedBy") != nil {
        var UUIDarray = object.valueForKey("likedBy")? as NSArray
        var uuidArray:[String] = UUIDarray as [String]
        if !isStringPresentInArray(uuidArray, str: uuid) {
            object.addObject(uuid, forKey: "likedBy")
            object.incrementKey("count")
            object.saveInBackground()
            let count = object.valueForKey("count") as Int?
            //cell.count.text = "\(count)"
            self.tableView.reloadRowsAtIndexPaths([hitIndex!], withRowAnimation: UITableViewRowAnimation.None)

这只会正确地重新加载单元格,但是,现在我的整个表格 View 总是滚动到顶部,这并不理想。

最佳答案

我不明白你想用 UUID 做什么; hitpoint ;hitIndex,我不明白你想让你的应用程序做什么,而且我没有 parse 经验?我会评论你的问题,但我需要 50 个代表才能做到这一点。抱歉,这不是答案,而是一个问题。如果你指的是 cellForRowAtIndexPath,你需要一个 UITableView 而不是一个单元格。

关于swift - 重新加载 PFTableViewCell 中的单行 - 返回 PFTableViewCell 没有 cellForRowMethod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29712059/

相关文章:

使用 self 进行 Swift 惰性实例化

ios - 如何在 iOS 中使用 PFQuery 获取表中的所有数据?

ios - Xcode无法将内容解析为info.plist

ios - 将 Parse.com 1.11.0 添加到 watchOS 2

JavaFX 表格 View 颜色

ios - 禁用表格 View 上的突出显示

ios - Swift 3 - 即使应用程序在后台运行功能

ios - 选择单元格后的事件指示器

swift - 如何在 SwiftUI 中从 Color 获取 RGB 分量

swift - 获取tableView内容的全高