スワイプ削除機能を追加
HistoryViewController.swift
// スワイプ削除
func tableView(tableView: UITableView,canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
{
return true
}
Deleteとでる部分のメッセージを変更する場合。
HistoryViewController.swift
override func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
return "削除"
}
スワイプ削除時の処理
HistoryViewController.swift
// 削除処理
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
// これはRealmSwiftでデータを削除しているケース
let deleteHistory = self.result![indexPath.row]
// トランザクションを開始してオブジェクトを削除します
try! realm!.write {
realm!.delete(deleteHistory)
}
// TableViewを再読み込み.
self.table.reloadData()
}
}