有没有办法在UITableView中强制刷新一个标题?

时间:2012-01-04 18:46:46

标签: iphone objective-c uitableview

我有一个UITableView,我想强制刷新一个特定的部分标题行,而不是数据行。例如,刷新第3部分的标题。我知道如何重新加载整个部分(标题加数据),但是只能更新部分标题?

编辑:当表格的一个部分中的数据发生变化时,我想更新不同部分标题中的信息。因此,我需要获取节标题的引用,然后刷新它。

4 个答案:

答案 0 :(得分:11)

如果标头是自定义UIView,那么您只需拨打setNeedsDisplay上的UIView而不是UITableView

答案 1 :(得分:7)

嗯,就我而言,在完成一些异步任务之后,我需要更新自定义部分标题视图。

我用它来更新它的高度: 此Swift 3+代码

//to reload your cell data
self.tableView.reloadData()
DispatchQueue.main.async {
// this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
  self.tableView.beginUpdates()
  self.tableView.endUpdates()
}        

答案 2 :(得分:1)

UITableView没有任何此类方法只重新加载标题视图/标题...您必须重新加载整个部分或表格。

答案 3 :(得分:-3)

我不同意见。我在使用自定义节标题删除行时遇到了这种情况,并且(至少在iOS 6中)您只需调用:

[self tableView:self.tableView viewForHeaderInSection:[indexPath section]];

只要您有适当的代码在该方法中返回视图,您就可以轻松刷新特定部分的标题:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    if ([self tableView:tableView numberOfRowsInSection:section] == 0) {

        return nil; //hide the header if there are no rows...

    } else {
        // configure or refresh the header...
    }
}
相关问题