我添加了一个标题 View 并向左滑动到 TableView Controller 。
正如您在屏幕截图中看到的那样,当我滑动行时标题 View 也会移动,请帮助我。
我添加标题的代码是
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableCell(withIdentifier: "HeaderCell") as! CustomHeaderTableViewCell
header.SortButton?.backgroundColor = UIColor(netHex:0xEEEEEE)
header.FilterButton?.backgroundColor = UIColor(netHex:0xEEEEEE)
header.SortButton?.font = UIFont.fontAwesome(ofSize: 18)
header.SortButton?.text = String.fontAwesomeIcon(name: .sort) + " Sort"
header.FilterButton?.font = UIFont.fontAwesome(ofSize: 18)
header.FilterButton?.text = String.fontAwesomeIcon(name: .filter) + " Filter"
return header
}
func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let more = UITableViewRowAction(style: .normal, title: "More") { action, index in
print("more button tapped")
}
more.backgroundColor = .lightGray
let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
print("favorite button tapped")
}
favorite.backgroundColor = .orange
let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
print("share button tapped")
}
share.backgroundColor = .blue
return [share, favorite, more]
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
searchBar.endEditing(true)
let translation = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
if(translation.y > 0)
{
// react to dragging down
} else
{
// react to dragging up
}
}
请帮我解决滑动问题。
还有一件事我可以隐藏滚动上的标题 View 。
最佳答案
您的问题有 2 种可能的解决方案:
- 只需在
viewForHeaderInSection
函数中返回cell.contentView
而不是 cell,您的问题就会得到解决。 - 子类
UITableViewHeaderFooterView
而不是UITableViewCell
用于您的页眉 View 。
关于ios - 如何向 uiTableView Controller 添加滑动和标题 View 。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42292128/