cellの削除の方法が知りたくて、
http://qiita.com/The_Shimon/items/7f93e82b0a043008e227
こちらのサイトを参考にさせていただき、私の場合はcellの上にボタンを配置して
それを押すとcellが削除できるという実装をしました。
ボタンのaction部分が以下です。
@IBAction func deletecell(_ sender: UIButton) { let alertController = UIAlertController(title: "", message:"削除しますか?", preferredStyle: UIAlertControllerStyle.alert) let actionOK:UIAlertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default ,handler:{ (action:UIAlertAction!) -> Void in print("OK") let cell = sender.superview?.superview as? UITableViewCell let indexPath = self.table.indexPath( for: cell! ) self.table.beginUpdates() self.image.remove(at: (indexPath?.row)!) self.table.deleteRows(at: [indexPath!], with: .fade) self.table.endUpdates() }) let cancelAction:UIAlertAction = UIAlertAction(title: "Cancel",style: UIAlertActionStyle.cancel, handler:{ (action:UIAlertAction!) -> Void in print("Cancel") }) // addActionした順に左から右にボタンが配置されます alertController.addAction(actionOK) alertController.addAction(cancelAction) self.present(alertController, animated: true, completion: nil) }
そしてcellに表示させているものはUIImage型のimageです。
このimageの数はサーバーから取得してくるので動的ですが、
今回はUIImage型の配列に5つの情報が入っているものとします。
私は、削除したものは次回以降表示させたくありませんが、
table.reloadや再度ページを表示した際にまた5つ表示されてしまいます。userdefaultなどで削除したものを記憶しておいて、
それを除けばいいのかもしれませんが、いまいちやり方が分かりません。
また、userdefaultはUIImage型を保存できず、
NSData型に変換しなければならないやら、それはお勧めできないやら、
やり方がわかりません。何か少しでも知っている方がいたら、
考え方など教えていただけたら幸いでございます。