如上图,在第一个section它的头部比其他section大,只是为何?如何解决?
相关代码
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake((SCREEN_WIDTH-200)/2, 10, 200, 25);
label.backgroundColor = [UIColor clearColor];
label.textColor = BarCOLOR;
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
label.textAlignment = NSTextAlignmentCenter;
label.text = sectionTitle;
// Create header view and add label as a subview
UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)];
[sectionView setBackgroundColor:[UIColor blackColor]];
[sectionView addSubview:label];
return sectionView;
return nil;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"12232211";
}
(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 22;
}
(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section设置返回为0
一个section它的头部没有比其他section大,那是导航栏
sention 头部你没有单独设置的话都是等高的,你上边应该是有一个导航栏 self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; n
你还可以设置导航栏的隐藏属性 self.navigationController.navigationBarHidden = NO; NO是设置不隐藏
(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 22;
}
(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.0000001;
}