Ios UITableView-获取HeaderInHeaders的现有视图

Ios UITableView-获取HeaderInHeaders的现有视图,ios,uitableview,Ios,Uitableview,我想在UITableView中获取现有的标题视图,以便更新它们的外观。我找不到类似visibleCells的方法,该方法将返回标题视图而不是单元格。这是可能的,还是我应该在创建过程中存储这些视图?您应该将它们存储在NSMutableArray中。以下是一些示例代码: [tableView headerViewForSection:sectionNum]; @interface ViewController : UITableViewController (UITableViewDataSour

我想在UITableView中获取现有的标题视图,以便更新它们的外观。我找不到类似visibleCells的方法,该方法将返回标题视图而不是单元格。这是可能的,还是我应该在创建过程中存储这些视图?

您应该将它们存储在NSMutableArray中。以下是一些示例代码:

[tableView headerViewForSection:sectionNum];
@interface ViewController : UITableViewController (UITableViewDataSource, UITableViewDelegate)
@property (nonatomic, strong) NSMutableArray *sectionHeaderViews;
@end


@implementation ViewController

- (void)viewDidLoad {
  self.sectionHeaderViews = [NSMutableArray array];
  NSInteger numOfSections = [self numberOfSectionsInTableView:self.tableView];
  for(int i=0; i<numOfSections)
  {
     CustomHeaderView *headerView = [[CustomHeaderView alloc] init];

     // customize headerView here
     ...

     [self.sectionHeaderViews addObject:headerView];
  }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  return [self.sectionHeaderViews objectAtIndex:section];
}

- (void)updateViewForSection:(NSInteger)section {
  CustomHeaderView *headerView = [self.sectionHeaderViews objectAtIndex:section];

  // update headerView here
  ...

  // reload section
  [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic];
}

@end
@interface ViewController:UITableViewController(UITableViewDataSource,UITableViewDelegate)
@属性(非原子,强)NSMutableArray*sectionHeaderViews;
@结束
@实现视图控制器
-(无效)viewDidLoad{
self.sectionHeaderViews=[NSMutableArray];
NSInteger numOfSections=[self numberOfSectionsInTableView:self.tableView];

对于(int i=0;我使用的是6.0之前的标题,而不是UITableViewHeaderFooterView。在这种情况下,您可能应该将视图按节存储在NSArray中。这正是我所担心的。我明白了他们为什么引入UITableViewHeaderFooterView。谢谢!UITableViewHeaderFooterView的好处是,您可以像使用wit一样将它们重新定义为可重用h常规单元格,但这当然需要您的最低部署目标为iOS 6.0及以上。顺便说一句,我还使用了Sensive TableView框架,其中每个部分都有一个名为“headerView”的属性,您可以随时修改。还值得一看,以了解许多其他可能有用的功能。