ios - Table View Data Loading Multiple Times After Dismissing Modal View Controller -


i have table view displays objects parse. have button modally presents view controller adding new objects. when row in table view selected, modally presents view controller display objects info , allows object edited. issue i'm having when add new item or edit item , dismiss modal controller, table view reloads , displays data multiple times. have done wrong?

these functions in presenting view controller (my table view controller). issue has in diddismissviewcontroller().

func getitems() {         // activityindicator?.startanimating()          let query = pfquery(classname: "items")         query.wherekey("user", equalto: pfuser.currentuser()!)         query.wherekey("collection", equalto: self.title!)         query.orderbyascending("item")         query.limit = limit         query.skip = skip         query.findobjectsinbackgroundwithblock( {             (objects, error) -> void in             if error == nil {                 if let objects = objects [pfobject]! {                     object in objects {                         self.itemnames.append(object["item"] as! string)                         self.objectid.append(object.objectid!)                         self.itemupc.append(object["upc"] as! string)                         self.model.append(object["model"] as! string)                         self.pricepaid.append(object["pricepaid"] as! string)                         // self.imagesarray.append(object["images"])                         if object["images"] == nil {                             self.imagesarray.append(nil)                         } else {                             self.imagesarray.append(object["images"])                         }                     }                 }                 // print(self.imagesarray)                  /*                 if objects!.count == self.limit {                 self.skip += self.limit                 self.getcollections()                 }                 */                  dispatch_async(dispatch_get_main_queue()) {                     self.tableview.reloaddata()                     // self.activityindicator!.stopanimating()                     print(self.itemnames)                 }             } else {                 var errorstring = string()                 if let message = error!.userinfo["error"] {                     errorstring = message as! string                 }                  print(errorstring)             }         })     }      func createitem() {         let createvc = createitemviewcontroller(nibname: "createitemviewcontroller", bundle: nil)         let navcontroller = navcontroller(rootviewcontroller: createvc)         navcontroller.modalpresentationstyle = .overcurrentcontext         createvc.collectionstring = self.title!         nsnotificationcenter.defaultcenter().addobserver(self, selector: "diddismissviewcontroller", name: "itemadded", object: nil)         self.presentviewcontroller(navcontroller, animated: true, completion: nil)     }      func diddismissviewcontroller() {         objectid.removeall()         itemnames.removeall()         itemupc.removeall()         pricepaid.removeall()         model.removeall()         imagesarray.removeall()         itemimages.removeall()         getitems()     } 

this function in modally presented view controller enter item details parse object want create.

func done() {         // save item data...          if itemimageview.image != nil {             let picturedata = uiimagejpegrepresentation(itemimageview.image!, 0.05)             image = pffile(name: "img", data: picturedata!)         } else {             image = nil         }          let newitem = pfobject(classname: "items")         newitem["item"] = itemnametextfield.text         newitem["upc"] = upctextfield.text         newitem["model"] = modeltextfield.text         newitem["pricepaid"] = pricepaidtextfield.text         newitem["user"] = pfuser.currentuser()         newitem["collection"] = collectionstring         newitem["images"] = itemimages           newitem.saveinbackgroundwithblock( {             (succeeded, error) -> void in             if error == nil {                 nsnotificationcenter.defaultcenter().postnotificationname("itemadded", object: nil, userinfo: nil)                 self.presentingviewcontroller?.dismissviewcontrolleranimated(true, completion: nil)             } else {                 var alert: uialertcontroller?                 let errorok = uialertaction(title: "ok", style: .default, handler: {                     (action) -> void in                     alert?.dismissviewcontrolleranimated(true, completion: nil)                 })                 var errorstring = string()                 if let message = error!.userinfo["error"] {                     errorstring = message as! string                 }                 alert = uialertcontroller(title: "error", message: errorstring, preferredstyle: .alert)                 alert!.addaction(errorok)                 self.presentviewcontroller(alert!, animated: true, completion: nil)             }         })     } 

it appears you're adding observers, not removing them.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -