heightForHeaderInSection不工作
我试图让heightForHeaderInSection设置我的部分标题的高度,但它似乎并没有工作。 我已经把这个
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 60.0f; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSString *SectionHeaderViewIdentifier = @"sectionHeaderIndentifier"; HeaderSection *sectionHeaderView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionHeaderViewIdentifier]; return sectionHeaderView; }
在我的ViewController.m文件中。
下面是它在模拟器中不工作的截图。
我也应该说我在我的ViewController的ViewDidLoad注册了笔尖。
UINib *sectionHeaderNib = [UINib nibWithNibName:@"headerNib" bundle:nil]; NSString *SectionHeaderViewIdentifier = @"sectionHeaderIndentifier"; [self.tableView registerNib:sectionHeaderNib forHeaderFooterViewReuseIdentifier:SectionHeaderViewIdentifier];
这是故事板布局和连接。
viewForHeaderInSection应该是这样的:
myLabel = [[UILabel alloc] init]; headerView = [[UIView alloc] init]; myLabel.frame = CGRectMake(10, 0, self.view.bounds.size.width, 20); myLabel.text = [self tableView:self.meetingOverviewTable titleForHeaderInSection:section]; [headerView setBackgroundColor:[UIColor lightGrayColor]]; [headerView addSubview:myLabel]; return headerView;