Ios 如何使用UITableView页脚和页眉显示上下边框?

Ios 如何使用UITableView页脚和页眉显示上下边框?,ios,objective-c,Ios,Objective C,我需要有UITableView的上下边框。为此,我决定使用高度为1点的表格页眉和页脚。我使用事件viewForHeaderInSection和viewforfootensection。我的问题是页眉和页脚很厚 我不知道这是否是正确的解决方案,我也不知道如何修复页眉和页脚的大小 我使用以下代码: -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *

我需要有
UITableView
的上下边框。为此,我决定使用高度为1点的表格页眉和页脚。我使用事件
viewForHeaderInSection
viewforfootensection
。我的问题是页眉和页脚很厚

我不知道这是否是正确的解决方案,我也不知道如何修复页眉和页脚的大小

我使用以下代码:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1)];

    [view setBackgroundColor:[UIColor blueColor]];

    return view;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1)];

    [view setBackgroundColor:[UIColor blueColor]];
    return view;
}

您忘记了这两种方法,它们都有默认高度:

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0;
 }
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 1.0;
}

再添加两个代理方法
heightForHeaderInSection
heightforfootensection
。并将其高度返回为1。