ios - segue from UIViewController to UITableViewController -


i'm trying segue data uiviewcontroller uitableviewcontroller. data in uiviewcontroller coming pftableviewcontroller , want pass data tableviewcontroller.

for passing viewcontroller didselect method used have no idea how can segue viewcontroller tableviewcontroller.

override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {     let destinationtofvc:viewcontroller = self.storyboard!.instantiateviewcontrollerwithidentifier("fvcont") as! viewcontroller      if let indexpath = self.tableview.indexpathforselectedrow {         let row1 = int(indexpath.row)         destinationtofvc.currentobject = objects?[row1] as! pfobject!       }     navigationcontroller?.pushviewcontroller(destinationtofvc, animated: true)  } 

i'm new programming.

in case can launch segue manually didselectrowatindexpath, the method performseguewithidentifier.

you need create custom segue in storyboard uiviewcontroller uitableviewcontroller , set identifier it, can press ctrl + click uiviewcontroller next create custom segue , select segue , in attributes inspector set identifier segue picture:

enter image description here

then can in didselectrowatindexpath launch segue manually in code:

override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {      // identifier of segue same set in attributes inspector      self.performseguewithidentifier("mysegueid", sender: self) } 

and of course need implement method prepareforsegue pass data uiviewcontroller uitableview in code:

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if (segue.identifier == "mysegueid") {         // in line need set name of class of `uitableviewcontroller`          let viewcontroller = segue.destinationviewcontroller uitableviewcontroller         let indexpath = self.tableview.indexpathforselectedrow()         destinationtofvc.currentobject = objects?[indexpath] as! pfobject!     } } 

edit:

if want perform segue uibutton uitableviewcontroller it's same logic, create custom segue in storyboard , call prepareforsegue in following code:

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {    if (segue.identifier == "mysegueid") {        // in line need set name of class of `uitableviewcontroller`         let viewcontroller = segue.destinationviewcontroller uitableviewcontroller        / here need pass data using reference viewcontroller    } } 

i hope you.


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 -