逐月

技术博客

IOS reload rows of secitons or a specific section

摘自我在SO 问题Reload tableView section without reloading header section - Swift回答,如果觉得有帮助,请移步SO给个upvote.


只需要code的话,这一段就够了

var indexPaths = self.tableView.indexPathsForVisibleRows

/* just roload visible rows of specified section
indexPaths = indexPaths.filter({ (indexPath) -> Bool in
    return indexPath.section == SECTION_INDEX_NEED_TO_RELOAD
})
*/
self.tableView.reloadRows(at: indexPaths!, with: .none)

Note:

  • UITableView.reloadData() will reload all the table. Docs about reloaddata

    reload all the data that is used to construct the table, including
    cells, section headers and footers, index arrays, and so on. For
    efficiency, the table view redisplays only those rows that are
    visible. It adjusts offsets if the table shrinks as a result of the
    reload. The table view’s delegate or data source calls this method
    when it wants the table view to completely reload its data.

  • UITableView.reloadSections(_ sections: IndexSet, with animation: UITableViewRowAnimation) will reload specific section( including section header and section footer). Docs about reloadsections

  • UITableView.reloadRows(at indexPaths: [IndexPath], with animation: UITableViewRowAnimation) will reload the specified rows. Docs about reloadRows

So here reloadSections will not works here. If your header section data and status not change, call this method will make no diffrence by sight.

Solution: use reloadRows to load the rows of all the sections or of the specific section. Note: here you can just load the visible rows, others will be loaded when you scroll you view. You also can refer to Get all indexPaths in a section for more solutions

var indexPaths = self.tableView.indexPathsForVisibleRows

/* just roload visible rows of specified section
indexPaths = indexPaths.filter({ (indexPath) -> Bool in
    return indexPath.section == SECTION_INDEX_NEED_TO_RELOAD
})
*/
self.tableView.reloadRows(at: indexPaths!, with: .none)
阅读更多
个人分类: IOS Xcode UITableView
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

IOS reload rows of secitons or a specific section

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭