我有一个带有 a 的自定义视图UILabel
,UIButton
我将其用于分组的UITableView
部分标题,如下所示:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
sectionHeaderView *headerView = [[sectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
[headerView.label setText:[[self tableView:tableView titleForHeaderInSection:section] uppercaseString]];
if (_tableView.editing)
[headerView.button setHidden:NO];
return headerView;
}
如您所见,我想在UITableView
处于编辑模式时取消隐藏按钮。
我使用UITableView
类别方法返回 visibleHeaders,这样我就可以在不调用 reloadData 或 reloadSections:withRowAnimation 的情况下刷新可见的节标题视图。该方法基本上返回一个 NSNumber 对象数组,并且效果很好。
这是UITableView
在编辑模式下设置的方法:
- (void)tapThatEditButtonBaby
{
[_tableView setEditing:YES animated:YES];
for (NSNumber *sectionNumber in _tableView.visibleHeaders) {
NSInteger section = [sectionNumber integerValue];
sectionHeaderView *headerView = (sectionHeaderView *)[self tableView:_tableView viewForHeaderInSection:section];
[headerView setBackgroundColor:[UIColor redColor]]; // highlighting view for testing.
}
}
解决这个问题的好方法是什么?理想情况下,在我看来,我希望能够调用诸如 updateSectionAndFooterAtIndex: from 之类的东西UITableView
,但是没有这种公开的方法... :(