しめ鯖日記

swift, iPhoneアプリ開発, ruby on rails等のTipsや入門記事書いてます

UITableViewCellEditingStyleでnoneを選んだ時にできる空白スペースを削除する

UITableViewCellで、削除ボタンを出さなくした時のスペースを消す方法です。

内容

UITableViewでは以下のようなメソッドを実装する事で編集中に削除ボタンを出さない事ができます。

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

しかし消すだけだと左側にスペースが残ってしまいます。

f:id:llcc:20160924131603p:plain

shouldIndentWhileEditingRowAtを実装する事でスペースを消す事ができます。

override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

f:id:llcc:20160924131742p:plain