ios - collection view cells fetch data -


i new collection view. want retrieve data coredata collection view cell. know how retrieve table view cell failed when use similar way fetch collection view. here functions coredatahelper , viewcontroller class

override func prepare(for segue: uistoryboardsegue, sender: any?) {     if let identifier = segue.identifier {         if identifier == "displaycelldetail" {             print("task view cell tapped")         collectionviewcoredatahelper.retrievetasks()       let indexpath = collectionview.indexpathsforselecteditems!           let task = tasks[indexpath.row]     let tasksettingviewcontroller = segue.destination as! viewcontroller             tasksettingviewcontroller.task = task          } else if identifier == "addtask" {             print("+ button tapped")         }     } }   static func retrievetasks() -> [tasks] {     let fetchrequest = nsfetchrequest<tasks>(entityname: "tasks")     {         let results = try managedcontext.fetch(fetchrequest)         return results     } catch let error nserror {         print("could not fetch \(error)")     }     return [] } 

try :

 override func prepare(for segue: uistoryboardsegue, sender: any?) {         if let identifier = segue.identifier {             if identifier == "displaycelldetail" {                 print("task view cell tapped")        collectionviewcoredatahelper.retrievetasks()        let cell = sender as? yourcellname //cell segue being performed       let indexpath = self.collectionview!.indexpathforcell(cell)                      let task  = self.tasks[indexpath.item] //downcast type of  task        let objtasksettingvc = segue.destination as! tasksettingviewcontroller              objtasksettingvc.tasks = task           }      else if identifier == "addtask" {             print("+ button tapped")         }       }     } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -