【发布时间】:2018-01-16 20:18:13
【问题描述】:
我正在尝试让 UIButton(或可点击的 UIView)出现在 UITableView 上方。这很容易。困难的部分是当用户向下滚动表格视图时使其滚动。
我尝试过像这样使用 UIScrollView:
private var scroll = UIScrollView();
private var table = UITableView();
override func viewDidLoad()
{
super.viewDidLoad()
scroll = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height));
table = UITableView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height));
table.register(ATableCell.self, forCellReuseIdentifier: "reuseIdentifier");
table.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0);
table.backgroundColor = UIColor.clear;
table.separatorInset = .zero;
table.layoutMargins = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10);
table.rowHeight = UITableViewAutomaticDimension;
// table.estimatedRowHeight = 100;
table.dataSource = self;
table.delegate = self;
scroll.addSubview(table);
self.view.addSubview(table);
}
顶部的滚动条空间可以容纳一个按钮,但始终存在。我希望它保持在表格视图上方,但在用户向下滚动时失去焦点(如网页或 iphone 中的标准邮件应用程序,它通过搜索栏和表格视图执行此操作)。谢谢。
【问题讨论】:
-
你试过
tableHeaderView吗? -
在 UITableView 的页眉和页脚中?我有一些部分,但我不希望标题像它那样留在那里。
-
如何使用tableHeaderView?感谢您的帮助。
-
您不能在表格的第一个单元格中添加按钮吗?
-
设置你的tableview样式
Grouped,然后设置tableHeaderView,它将随着tableview滚动。
标签: ios swift uitableview swift3 uiscrollview