swift - Passing Core Data objects from UITableViewCell to another View Controller -


currently have application loading data in tableview presented user want them select object wish view further details about. want able read out data in object user in various forms either labels or tableview dependent on data.

i have been reading around , trying understand stuff still new me! had guy on here me out saving data , passing data around store reading out seemingly different thing. examples in swift language lead me down right path know need use didselectrow method , call segue , need prepare segue not quite sure how should look.

i have read multiple posts , attempt pass objects not in manner in trying to..are able pass whole objects after have been have been selected in tableview view controller present data related object or able pass information object next viewcontroller? have examples of prepareforsegue , perform segue before not sure else missing not able pass information between tableview , viewcontroller.

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) {     if (segue.identifier == "decktorecord") {          var detailvc: statwidgetviewcontroller = segue.destinationviewcontroller as! statwidgetviewcontroller          detailvc.deckrecord = decktopass      }  }  func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {      let indexpath = tableview.indexpathforselectedrow()      let selectedcell = tableview.cellforrowatindexpath(indexpath!) uitableviewcell?      self.performseguewithidentifier("decktorecord", sender: indexpath);  } 

decktopass variable contains type of data entity primary entity of object.

a little confused you're asking understand, once user clicks on cell want segue view controller can edit the details?

to add exception breakpoint, open left panel files/viewcontrollers, @ top of should small panel few icons, first 1 folder, click on second last 1 (the 1 looks tag) click on plus in bottom right , click add exception breakpoint, should let know problem in code occurring

okay edit details in view controller start preparing segue original view controller

 override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {          if segue.identifier == "showtaskdetail" {             let detailvc: taskdetailviewcontroller = segue.destinationviewcontroller as! taskdetailviewcontroller             let indexpath = self.tableview.indexpathforselectedrow()             let thistask = fetchedresultscontroller.objectatindexpath(indexpath!) as! taskmodel             detailvc.detailtaskmodel = thistask             detailvc.delegate = self          }         else if segue.identifier == "showtaskadd" {             let addtaskvc:addtaskviewcontroller = segue.destinationviewcontroller as! addtaskviewcontroller             addtaskvc.delegate = self         }     } 

okay code showing above, have segue called showtaskdetail shows details of whatever is, in case simple task. said want edit information in view controller when user clicks on row, need able information in other view controller.

so create variable in other viewcontroller hold these values, me called detailtaskmodel

 var detailtaskmodel: taskmodel! 

incase you're confused taskmodel is, i'm using coredata store data, , taskmodel nsmangedobject class.

let detailvc: taskdetailviewcontroller = segue.destinationviewcontroller as! taskdetailviewcontroller 

this line you're specifying other view controller is, replace taskdetailviewcontroller swift class.

let detailvc: taskdetailviewcontroller = segue.destinationviewcontroller as! taskdetailviewcontroller 

this line fetches data row selected

now should able pass information other view controller , edit using detailtaskmodel, need well?


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -