【发布时间】:2014-07-01 08:25:33
【问题描述】:
我有一个带有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.
}
}
解决这个问题的好方法是什么?理想情况下,在我看来,我希望能够从UITableView 调用诸如 updateSectionAndFooterAtIndex: 之类的东西,但是没有这种暴露的方法...... :(
【问题讨论】:
标签: ios objective-c uitableview custom-view sectionheader