Reload sections in UITableView

后端 未结 6 2396
执笔经年
执笔经年 2021-02-13 11:34

I am writing an app that notifies user when its time to take his/her medicine. The label at the top of the page shows a date and the tableView gets populated with m

6条回答
  •  野性不改
    2021-02-13 12:04

    There are few functions supported in UITableView for reloading data. See section Reloading the Table View of doc.

    • reloadData
    • reloadRowsAtIndexPaths:withRowAnimation:
    • reloadSections:withRowAnimation:
    • reloadSectionIndexTitles

    Also, see this similar thread, a part from it:

    NSRange range = NSMakeRange(0, 1);
    NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];                                     
    [self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];
    

    Also, it is not necessary to reload specific sections, you can just adjust your dataset and call [tableView reloadData], it will load the visible cells only. A part from doc:

    Call this method to 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.

提交回复
热议问题