我正在尝试使UIButton(或可点击的UIView)出现在UITableView上方。这很容易。最困难的部分是当用户向下滚动表格视图时滚动。添加一个按钮,在Swift中使用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的页眉和页脚?我有一些部分,但我不希望标题像它那样呆在那里。 – cdub
如何使用tableHeaderView?谢谢你的帮助。 – cdub