swift - Delete user row in Parse Data browser -


import uikit  class listeutilisateurspfquerytableviewcontroller: pfquerytableviewcontroller, uisearchbardelegate {      var images = [nsdata]()      var userobjects: nsmutablearray = nsmutablearray()      // table search bar     @iboutlet weak var searchbar: uisearchbar!      // initialise pfquerytable tableview     override init!(style: uitableviewstyle, classname: string!) {         super.init(style: style, classname: classname)     }      required init(coder adecoder: nscoder) {         super.init(coder: adecoder)          // configure pfquerytableview         self.parseclassname = "_user"         self.textkey = "username"         self.pulltorefreshenabled = true         self.paginationenabled = false     }      // define query provide data table view     override func queryfortable() -> pfquery! {          userobjects.removeallobjects()          var query = pfuser.query()          object in objects{             let user: pfobject = object pfobject             self.userobjects.addobject(user)         }          let array:nsarray = self.userobjects.reverseobjectenumerator().allobjects         self.userobjects = nsmutablearray(array: array)          self.tableview.reloaddata()         self.refreshcontrol?.endrefreshing()           if searchbar.text != "" {             query.wherekey("searchtext", containsstring: searchbar.text.lowercasestring)         }          query.orderbyascending("username")          return query     }      override func viewdidload() {         super.viewdidload()     }       func searchbartextdidendediting(searchbar: uisearchbar) {          // dismiss keyboard         searchbar.resignfirstresponder()          // force reload of table data         self.loadobjects()     }      func searchbarsearchbuttonclicked(searchbar: uisearchbar) {          // dismiss keyboard         searchbar.resignfirstresponder()          // force reload of table data         self.loadobjects()     }      func searchbarcancelbuttonclicked(searchbar: uisearchbar) {          // clear search criteria         searchbar.text = ""          // dismiss keyboard         searchbar.resignfirstresponder()          // force reload of table data         self.loadobjects()     }      override func viewdidappear(animated: bool) {          // refresh table ensure data changes displayed         tableview.reloaddata()      }      // in storyboard-based application, want little preparation before navigation     override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {          // new view controller using [segue destinationviewcontroller].         var detailscene = segue.destinationviewcontroller utilisateurtableviewcell          // pass selected object destination view controller.         if let indexpath = self.tableview.indexpathforselectedrow() {             let row = int(indexpath.row)             detailscene.currentobject = objects[row] as? pfobject         }     }      //override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell     override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject) -> pftableviewcell {          var cell = tableview.dequeuereusablecellwithidentifier("cell") customtableviewcell!         if cell == nil {             cell = customtableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "cell")         }          // extract values pfobject display in table cell         cell.nomutilisateur.text = object["username"] string!         cell.statusutilisateur.text = object["status"] string!          if (cell.statusutilisateur.text == "medecin"){             cell.statusutilisateur.textcolor = uicolor.bluecolor()         }          if (cell.statusutilisateur.text == "client" || cell.statusutilisateur.text == "cliente"){             cell.statusutilisateur.textcolor = uicolor.lightgraycolor()         }          if (cell.statusutilisateur.text == "secrétariat"){             cell.statusutilisateur.textcolor = uicolor.browncolor()         }          var thumbnail = object["imagefile"] pffile         cell.photoutilisateur.file = thumbnail         cell.photoutilisateur.loadinbackground()          return cell     }      override func tableview(tableview: uitableview?, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath?) {          var selecteduser:pfobject = self.userobjects.objectatindex(indexpath!.row) pfobject         selecteduser.deleteinbackground()         self.userobjects.removeobjectatindex(indexpath!.row)         self.tableview.reloaddata()      } } 

i've problem removing user row in parse. lot of different solution on web made class moment can't delete user row in parse backend; when try error message :

2015-03-28 15:26:53.209 ios-ehpad[4446:610055] -[uiapplication endignoringinteractionevents] called without matching -beginignoringinteractionevents. ignoring. 2015-03-28 15:26:57.059 ios-ehpad[4446:610055] *** terminating app due uncaught exception 'nsrangeexception', reason: '*** -[__nsarraym objectatindex:]: index 2 beyond bounds empty array' *** first throw call stack: (     0   corefoundation                      0x000000010f78ea75 __exceptionpreprocess + 165     1   libobjc.a.dylib                     0x00000001112e6bb7 objc_exception_throw + 45     2   corefoundation                      0x000000010f679893 -[__nsarraym objectatindex:] + 227     3   ios-ehpad                           0x000000010df21a04 _tfc9ios_ehpad43listeutilisateurspfquerytableviewcontroller9tableviewfs0_ftgsqcso11uitableview_18commiteditingstyleosc27uitableviewcelleditingstyle17forrowatindexpathgsqcso11nsindexpath__t_ + 324     4   ios-ehpad                           0x000000010df21d8f _ttofc9ios_ehpad43listeutilisateurspfquerytableviewcontroller9tableviewfs0_ftgsqcso11uitableview_18commiteditingstyleosc27uitableviewcelleditingstyle17forrowatindexpathgsqcso11nsindexpath__t_ + 79     5   uikit                               0x000000011011a604 -[uitableview animatedeletionofrowwithcell:] + 130     6   uikit                               0x00000001100faa75 __52-[uitableview _swipeactionbuttonsforrowatindexpath:]_block_invoke + 72     7   uikit                               0x0000000110022a22 -[uiapplication sendaction:to:from:forevent:] + 75     8   uikit                               0x0000000110129e50 -[uicontrol _sendactionsforevents:withevent:] + 467     9   uikit                               0x000000011012921f -[uicontrol touchesended:withevent:] + 522     10  uikit                               0x0000000110068b68 -[uiwindow _sendtouchesforevent:] + 735     11  uikit                               0x0000000110069493 -[uiwindow sendevent:] + 683     12  uikit                               0x0000000110035fb1 -[uiapplication sendevent:] + 246     13  uikit                               0x0000000110043227 _uiapplicationhandleeventfromqueueevent + 17700     14  uikit                               0x000000011001e23c _uiapplicationhandleeventqueue + 2066     15  corefoundation                      0x000000010f6c3c91 __cfrunloop_is_calling_out_to_a_source0_perform_function__ + 17     16  corefoundation                      0x000000010f6b9b5d __cfrunloopdosources0 + 269     17  corefoundation                      0x000000010f6b9194 __cfrunlooprun + 868     18  corefoundation                      0x000000010f6b8bc6 cfrunlooprunspecific + 470     19  graphicsservices                    0x0000000111e4ca58 gseventrunmodal + 161     20  uikit                               0x0000000110021580 uiapplicationmain + 1282     21  ios-ehpad                           0x000000010df0c9de top_level_code + 78     22  ios-ehpad                           0x000000010df0cada main + 42     23  libdyld.dylib                       0x0000000112454145 start + 1     24  ???                                 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception (lldb)  

any idea problem?

you should follow of parse tutorials on how use pfquerytableviewcontroller, you're going @ wrong way.

first of all, manipulating objects array in queryfortable(). @ point query hasn't been run, array still empty, means userobjects array empty. if want go through results of query should in objectsdidload method.

but advise against it, because think trying here change how objects returned query ordered. should know if use pfquerytableviewcontroller, can't change content or ordering of query results. copying array in other array not work, because new array not use populate table view.

one among many consequences of cannot delete items in pfquerytableviewcontroller. if want delete items, should implement own controller. there may can use on github, encourage around, don't have 1 in mind right now.

if want specific understanding of crash, here : table view displays many objects (which stored in objects array). when tried delete object in table view, code tried remove object userobjects array, which, said above, empty. hence crash, cannot remove object empty array.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -