Reputation: 45
My UITableView
's style is plain, and I want to change the height of HeaderInSection, but it's remains the default height 22.0.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (tableView.tag == tableOrdersTag)
{
return 35;
}
else
{
return 0;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (tableView.tag == tableOrdersTag)
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frameWidth, 35)];
view.backgroundColor = COMMON_BACKGROUND_COLOR;
DDLogVerbose(@"=========tableView %f", tableView.sectionHeaderHeight);
return view;
}
else
{
return nil;
}
}
Upvotes: 2
Views: 150
Reputation: 8673
The place of your NSLog
DDLogVerbose(@"=========tableView %f", tableView.sectionHeaderHeight);
may cause the problem.It should's before the return method:
return view;
change the number 35 to 100, you'll find the it works fine.
because the method of
tableView:viewForHeaderInSection
is behind of
tableView:heightForHeaderInSection.
When I create a TaleViewController without xib or storyboard like :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
NSLog(@"heightForHeaderInSection");
return 100;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 100)];
view.backgroundColor = [UIColor redColor];
NSLog(@"=========tableView %f", tableView.sectionHeaderHeight);
return view;
}
it will print like :
2015-05-21 18:25:30.525 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.526 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.526 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.526 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.535 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.535 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.549 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.549 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
2015-05-21 18:25:30.550 UITableViewHeaderDemo[24727:2350493] =========tableView -1.000000
but the
Upvotes: 1
Reputation: 1502
Do this things:-
Try out this. Hope this will solve your problem.
Upvotes: 1
Reputation: 998
First of all change section height from Xib then
Return following line instead of nil in else then check
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frameWidth, 0)];
Upvotes: 0