ios - 如何向 uiTableView Controller 添加滑动和标题 View 。?

标签 ios uitableview swift3 swipe

this the first screenshort

enter image description here

我添加了一个标题 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 种可能的解决方案:

  1. 只需在 viewForHeaderInSection 函数中返回 cell.contentView 而不是 cell,您的问题就会得到解决。
  2. 子类 UITableViewHeaderFooterView 而不是 UITableViewCell 用于您的页眉 View 。

关于ios - 如何向 uiTableView Controller 添加滑动和标题 View 。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42292128/

相关文章:

ios - NSFetchedResultsController 只获取前 10 个项目

swift3 - 覆盖 Swift 和 SpriteKit 中类的开放变量以在 XCode 的 ActionEditor 中使用

ios - Firebase 未加载数据

ios - 如何让 SpriteKit Playgrounds 在 Xcode 8 beta 中工作?

ios swift UILabel 字体大小不会以编程方式更改

ios - 如何通过 AVAssetExportSession 设置 AVFileTypeMPEG4 文件的元数据?

ios - 为多个状态设置外观 - 有没有办法用更少的行来做到这一点?

ios - insertRowsAtIndexPaths 的断言失败

swift - TableView 没有使用正确的 TableViewCell

ios - UIButton 不可点击