UITableViewRowAction を実装する次の迅速なコードがあります。行をスワイプすると、期待どおりに行が左にスライドしますが、すべてのセクション ヘッダー行もテーブル行と同時に左にスライドします。
何が起こっているかを示すスクリーンショットも含めました
viewForHeader オーバーライドを削除して titleForHeaderInSection に置き換えれば、問題はありません。
viewForHeader をオーバーライドする理由は、ヘッダー行に画像を配置したいからです。
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) {
}