Ios 使用ViewForFooterInstition时,UITableView分隔符消失

Ios 使用ViewForFooterInstition时,UITableView分隔符消失,ios,objective-c,uitableview,Ios,Objective C,Uitableview,UITableView即使没有行也显示分隔符。但是当我使用viewforfooterInstitution时,分隔符消失了。我希望它继续出现。我该怎么办 下面是我在其中添加页脚时的代码: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)t

UITableView
即使没有行也显示分隔符。但是当我使用
viewforfooterInstitution
时,分隔符消失了。我希望它继续出现。我该怎么办

下面是我在其中添加页脚时的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"s"];

    cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row + 1];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;

    return cell;
}

// -------------------------- footer code start here --------------------------

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

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = [UIColor grayColor];

    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
    title.text = @"footer here";
    title.textAlignment = NSTextAlignmentCenter;
    title.textColor = [UIColor whiteColor];
    [view addSubview:title];

    return view;
}

此github项目可能会给您一些建议: 当然,如果希望页脚始终显示在屏幕上,即使有很多单元格,也需要进行一些更改。

删除
-(CGFloat)tableView:(UITableView*)页脚的tableView高度设置:(NSInteger)部分

-(UIView*)表视图:(UITableView*)表视图页脚位置:(NSInteger)部分

使用此代码可使页脚向下(但始终可见)并保留分隔符:

@implementation tableView {

__weak UIView *_staticView;

}

- (void)viewDidLoad {

UIView *staticView = [[UIView alloc] initWithFrame:CGRectMake(0, self.tableView.bounds.size.height-50, self.tableView.bounds.size.width, 50)];
staticView.backgroundColor = [UIColor redColor];
//add other code for UILabel here

[self.tableView addSubview:staticView];
_staticView = staticView;
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
_staticView.transform = CGAffineTransformMakeTranslation(0, scrollView.contentOffset.y);
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
 {
// this is needed to prevent cells from being displayed above our static view
[self.tableView bringSubviewToFront:_staticView];
 }

我猜你只有一个部分,对吗?在使用ViewForFooterInstitution之前,它只会一直填充空白单元格。但是,当调用ViewForFooterInstitution时,tableview会在节的末尾放置一个页脚。由于没有第二节,它会停止绘制任何单元格。因此,您可以创建空白的第二节,它会将空白单元格填充到第二部分。

您必须通过添加empthy数组来保持tableview的高度,以便在添加页脚时不会出现页脚,或者只需删除页脚并添加新的UIView,因为底部的页脚将是最佳选择!我尝试将
UIView
作为页脚添加到故事板中的
UITableView
中,结果是分隔符尚未显示。如何设置tableview的框架?您必须保持tableview的高度。只需缩短tableview的大小并添加一个视图,在viewdidload中以编程方式执行此操作,我想您会发现tableview的高度与设备高度相同(我使用autolayout)。我该怎么做才能让分离器继续出现?