不管UITableView iOS中的内容如何,​​我们可以使一个单元格出现在屏幕末端

时间:2019-02-21 05:23:42

标签: ios swift uitableview

无论UITableView iOS swift的内容如何,​​我都希望始终在屏幕末尾显示一个单元格

1 个答案:

答案 0 :(得分:0)

您可以添加表格页脚视图

使用StoryBoard

在TableView中,您可以拖动UIView,如果原型单元数多于0,它将设置为FooterView。拖动后,您可以在表视图层次结构中将其视为子视图。

以编程方式

遵循3个步骤

将一个自定义视图设为页脚视图, Swift 3.X / Swift 4.X

let customView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 50))

Swift 2.X

let customView = UIView(frame: CGRectMake(0, 0, 200, 50))

在表页脚视图中添加该视图。 Swift 2.X / Swift 3.X / Swift 4.X

myTblView.tableFooterView = customView

如果这不起作用,请尝试添加表格视图部分页脚 示例程序-

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

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *sampleView = [[UIView alloc] init];
    sampleView.frame = CGRectMake(SCREEN_WIDTH/2, 5, 60, 4);
    sampleView.backgroundColor = [UIColor blackColor];
    return sampleView;
}

并包括UITableViewDelegate协议。

@interface TestViewController : UIViewController <UITableViewDelegate>