Why do all section header lines slide with the table cell when I implement UITableViewRowAction

I have the following quick code to implement UITableViewRowAction, when I scroll the row, the row slides to the left, as expected, however all the header lines of the section also slide to the left with the table row at the same time.

I also included a screen shot to show what was happening.

If I remove the viewForHeader override and replace it with titleForHeaderInSection, then I have no problem.

The reason for overriding viewForHeader is that I want to put the image in the title bar.

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let cell = tableView.dequeueReusableCellWithIdentifier("header") as UITableViewCell cell.textLabel?.text = instrumentGroups[section].name cell.imageView?.image = UIImage(named: instrumentGroups[section].name) return cell } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> InstrumentTableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("instrumentCell", forIndexPath: indexPath) as InstrumentTableViewCell cell.instrument = instrumentGroups[indexPath.section].instruments[indexPath.row] return cell } override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { let instrument = instrumentGroups[indexPath.section].instruments[indexPath.row] var actions: [AnyObject] = [] var action = UITableViewRowAction(style: .Normal, title: "Remove Watch") { (action, indexPath) -> Void in tableView.editing = false instrument.SetWatchList(false) self.refresh() } action.backgroundColor = UIColor.redColor() actions.append(action) return actions } override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { } 

As I slide the row to the left all the Section Rows slide as well

+6
source share
2 answers

I had the same problem. The answer is simple. Because you are using a UITableViewCell as the title. Instead, try UILabel or UITableViewHeaderFooterView.

+6
source

Just return cell.contentView instead of cell in your viewForHeaderInSection function and your problem will be solved.

+23
source

Source: https://habr.com/ru/post/984163/


All Articles