Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

ios - Swipe to delete cell causes tableViewHeader to move with cell

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.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...