ios - Swift 3: Update table View after deleting the data from Core Data -


i trying remove , update data on table view. when mark profile "not favourite", deletes core database, however, still not removes table view. have 1 view controller ( profile view controller add favorite table) , other 1 table view controller ( favorite view controller). when click on 1st view controller add fav, saves record. when go second view controller see favs, can see list. now, remove 1 profile , mark not fav. able delete core database, but, table not reload. when restart app. see 1 marked not fav, removed still holds place on table view. when click on it, crashed down.

the code have:-

@ibaction func savefav(_ sender: uibutton) {     let propertytocheck = sender.currenttitle!     var proid = saved_id     let context = (uiapplication.shared.delegate as! appdelegate).persistentcontainer.viewcontext     let task = favprofile(context: context)      switch propertytocheck {     case "add favourite":      // link task & context     task.busname = bussinessname     task.profileid = int32(id!)!     print ("saved id is: - \(task.profileid)")     print ("saved profile name is: - \(task.busname)")     fav_remove_fav_button_label.settitle("remove favourite", for: .normal)      // save data coredata     (uiapplication.shared.delegate as! appdelegate).savecontext()      let _ = navigationcontroller?.popviewcontroller(animated: true)      let alert = uialertcontroller(title: "alert", message: "added favourite list", preferredstyle: uialertcontrollerstyle.alert)     alert.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil))     self.present(alert, animated: true, completion: nil)          case "remove favourite":                let fetchrequest = nsfetchrequest<nsfetchrequestresult>(entityname: "favprofile")             let predicate = nspredicate(format: "profileid == %@", id as! cvararg)             fetchrequest.predicate = predicate             let moc = getcontext()             let result = try? moc.fetch(fetchrequest)             let resultdata = result as! [favprofile]               object in resultdata {                 moc.delete(object)             }              {                 try moc.save()                 print("saved!")               //  notificationcenter.default.post(name: nsnotification.name(rawvalue: "load"), object: nil)                 let _ = navigationcontroller?.popviewcontroller(animated: true)             } catch let error nserror  {                 print("could not save \(error), \(error.userinfo)")             }                           let alert = uialertcontroller(title: "alert", message: "removed favourite list", preferredstyle: uialertcontrollerstyle.alert)         alert.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil))         self.present(alert, animated: true, completion: nil)       //  self.favtable.tableview.reloaddata()       default: break     } } 

please refer screen shots below:

this when save/ mark fav profile

this when save/ mark fav profile

this when mark not fav , restart app

this when mark not fav , restart app

this when use reload table view (fav) profile vc, don't have restart app

this when use reload table view (fav) profile vc, don't have restart app.


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 -