ios - Using Filters to Make Cells Delete Themselves -


fairly new coding!

i'm trying create user database firebase i'm able filter in app. figured easiest way toggle filters on view controller , use if statements have cells not meeting filter criterium delete themselves. i'm hoping have 6 or filters total, , think method scalable.

i can't figure out how cells delete themselves.

this page has single filter on it. prior view controller has button toggles "malefilter" between 1 , 0. when male filter 1, want users don't have "male" gender delete themselves. how might got doing that?

thanks!

///setup , grabbing database firebase

import uikit import alamofire import gloss  class usertableviewcontroller: uitableviewcontroller {  var user: user? var users: [user] = [] var myindex = 0 var malefilter: int?   override func viewdidload() {     super.viewdidload()     alamofire.request("https://database.firebaseio.com/users.json").responsejson(completionhandler: {         response in          if let usersdictionary = response.result.value as? json {              (key, value) in usersdictionary {                  if let usersdictionary = value as? json {                     var user = user(json: usersdictionary)                     user?.userkey = key                     self.users.append(user!)                     self.tableview.reloaddata()                 }             }         }     }) } 

///this i'm struggling
override func viewwillappear(_ animated: bool) { super.viewwillappear(true)

//malefilter has value toggled between 1 , 0 in prior view controller print(malefilter)  //malefilter == 1 represents filter being toggled on if malefilter == 1 {         if user?.usergender == "male" {             print ("male")         } else { 

i've tried code found online , can't work

            /*              users.remove(at: indexpath)              users.removeatindex(deletionindexpath.row)              tableview.deleterows(at: [indexpath.row], with: uitableviewrowanimation)              */ 

i've found online , been unable work

      /* let deleteaction = uitableviewrowaction(style: .destructive, title: "delete") { (rowaction: uitableviewrowaction, indexpath: indexpath) -> void in             func tableview(_ tableview: uitableview, commit editingstyle: uitableviewcelleditingstyle, forrowat indexpath: indexpath) {                  self.tableview.deleterows(at: [indexpath], with: .automatic)                 self.tableview.reloaddata()             }         }    */  } else {         print("male filter not applied")     }     self.tableview.reloaddata() } 

i feel answer simple. " self.users.remove(at: indexpath) (which doesn't work"

any appreciated

    filterarray = usersarray.filter({ m in m.usergender.contains("male") }) 

try 1 , in result u filter array male. hope you.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -