UITableView reload section

前端 未结 11 2102
余生分开走
余生分开走 2020-12-05 01:46

I want to reload only one section not the full table. Is there any method in UITableView.

[tableView reloadData] is used to load full table

11条回答
  •  醉酒成梦
    2020-12-05 02:27

    But you can reload only sections which contain same number of rows (or you have to manually add or remove them). Otherwise you will get an NSInternalInconsistencyException.

    Steps:

    1. calculate which rows to remove and/or insert
    2. generate an IndexPath array from these
    3. call related tableView methods

    now you can safely call reloadSections :) Reload section will call update for the rest of the indexes.

    Or you can use a library like : https://github.com/onmyway133/DeepDiff

    Swift pseodo code:

    
            tableView.deleteRows(at: valueIndexesToRemove, with: .automatic)
            tableView.insertRows(at: valueIndexesToInsert, with: .automatic)
            tableView.reloadSections(IndexSet([section]), with: .automatic)
    
    

提交回复
热议问题