Ios 更改UITableView';头部的高度是多少?
我的Ios 更改UITableView';头部的高度是多少?,ios,objective-c,Ios,Objective C,我的UITableView的样式很简单,我想更改HeaderInSection的高度,但它仍然是默认的高度22.0 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (tableView.tag == tableOrdersTag) { return 35; } else { retur
UITableView
的样式很简单,我想更改HeaderInSection的高度,但它仍然是默认的高度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;
}
}
首先从Xib开始改变截面高度,然后 在else中返回以下行而不是nil,然后检查
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frameWidth, 0)];
您的NSLog的位置
DDLogVerbose(@"=========tableView %f", tableView.sectionHeaderHeight);
可能导致问题。应在返回方法之前:
return view;
把35号改成100号,你会发现它很好用
因为
tableView:viewForHeaderInSection
落后于
tableView:heightForHeaderInSection.
当我创建没有xib或故事板的TaleViewController时,如:
- (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;
}
它的打印方式如下:
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
但是做这些事情:-
试试这个。希望这能解决您的问题。您是否设置了self.tableView.delegate=self?你这样做是正确的。将断点放在这些方法上&检查代码的哪一部分正在执行。@stevechen是的,我did@BC_Dilum这些方法执行正确,我已经检查过了。表视图中是否有多个部分,是否要更改所有部分的高度?另外,确保分配给表视图的标记是正确的。现在可以更改节的开头(我设置了55),但我将其设置为:-(void)tableView:(UITableView*)tableView didselectrowatinexpath:(nsindepath*)indepath{if(tableView.tag==tableOrdersTag){NSLog(@“桌面视图的节高度:===============:%f”,tableView.sectionHeaderHeight);}}}结果仍然是22.000000