在重新加载uitableviewcell,iOs / Swift时随机滚动

时间:2015-07-03 09:52:55

标签: ios swift uitableview

我正在开发新闻Feed,我正在使用uitableview来显示数据。我在其他线程中同步加载每个单元格数据并使用协议方法显示加载的数据:

func nodeLoaded(node: NSMutableDictionary) {
    for var i = 0; i < nodesArray.count; ++i {
        if ((nodesArray[i]["id"] as! Int) == (node["id"] as! Int)) {
            nodesArray[i] = node
            CATransaction.setDisableActions(true)
            self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
            CATransaction.setDisableActions(false)
        }
    }
}

问题在于,当我向下滚动(同时查看tableview)时,tableview将我推到了顶部。我正在寻找这个问题的答案,但没有什么可以帮助我。我已经尝试禁用动画了:

            CATransaction.setDisableActions(true)
            self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
            CATransaction.setDisableActions(false)

2)

            UIView.setAnimationsEnabled(false)
            self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
            UIView.setAnimationsEnabled(true)

但故事总是一样的。 当我不使用self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)时,我有了预期的效果 ,但在这种情况下,只有当我向下滚动然后返回到单元格时才重新加载数据。

也许问题是我每次使用自动布局和tableview重新计算其高度?但我不知道如何解决它

1 个答案:

答案 0 :(得分:0)

您可以自己构建重装机制。

迭代所有可见单元格(tableView.visibleCells),并像-tableView:cellForRowAtIndexPath:中一样对它们应用相同的逻辑。

如果您需要索引路径来执行此更新,您可以询问表格视图(-indexPathForCell:)。

相关问题