滑动以删除单元格会导致tableViewHeader与单元格一起移动 [英] Swipe to delete cell causes tableViewHeader to move with cell

查看:159
本文介绍了滑动以删除单元格会导致tableViewHeader与单元格一起移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 8中的 UITableView 上遇到了我的 tableViewHeader 的奇怪错误。在细胞上滑动时要显示删除按钮(标准iOS滑动到删除),它会移动 tableViewHeader 以及正在刷卡的单元格。当我滑动单元格时,标题的移动方式与刷过单元格的方式相同。表视图中没有其他单元格被移动,只有标题和任何单元格被刷过。我在iOS 7上测试过这个没有遇到过这个问题。对我来说,这似乎是iOS 8中 tableViewHeader 的一个错误,因为它只出现在这个版本中,看起来似乎永远不会发生。我认为没有理由将标题包含在滑动到删除中。

I have encountered a strange bug with my tableViewHeader on my UITableView in iOS 8. When swiping on a cell to reveal the delete button (standard iOS swipe-to-delete), it moves the tableViewHeader along with the cell that is being swiped. As I swipe the cell, the header moves in the same way that the cell being swiped does. No other cells in the table view are moved, only the header and whatever cell is being swiped. I have tested this on iOS 7 haven't encountered the problem. To me, this seems like a bug with tableViewHeader in iOS 8, being that it only occurs in this version and seems like something that should never occur. I see no reason for the header to ever be included in swipe-to-delete.

下面只是一个模型。在应用程序中滑动删除是默认的iOS,没有自定义。

Below is just a mockup. Swipe-to-delete within the app is default iOS, nothing custom.

推荐答案

基于ferris的答案,我发现使用UITableViewCell作为节头时最简单的方法是返回viewForHeaderInSection中单元格的contentView。代码如下:

Building on ferris's answer, I found the easiest way when using a UITableViewCell as a section header is to return the contentView of the cell in viewForHeaderInSection. The code is as follows:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let  cell : cellSectionHeader = tableView.dequeueReusableCellWithIdentifier("SectionHeader") as cellSectionHeader
    return cell.contentView
    //cellSectionHeader is my subclassed UITableViewCell
}

这篇关于滑动以删除单元格会导致tableViewHeader与单元格一起移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆