ios - Programmatically unwind segue -
i displaying uiview uitableview control on it. display view show segue, calling performseguewithidentifier. in module segue called, have added function want use on unwind, retrieve data view upon return segue. right now, have done button hooked function on caller, can retrieve data segue when unwinds. instead of doing when done button tapped, when item selected in uitableview.
in tableview(,willselectrowatindexpath), try calling popviewcontrolleranimated. second uiview close , bring me calling uiview, unwind function not called.
i know how set unwind done button, using exit, cannot figure out how when tapping on row in uitableview.
here's code i'm using execute segue:
@ibaction func frombuttontap(sender: anyobject) { currentbutton = sender.tag self.performseguewithidentifier("unitssegue", sender: self) }
here's code executes when segue unwound:
@ibaction func returnfromunitselection(segue: uistoryboardsegue) { var buttontoset: uibutton! var unitstoset: unitdata! fromlabel.text = "0" tolabel.text = "0" if let unitsselectionviewcontroller = segue.sourceviewcontroller as? unitselectioncontroller { if currentbutton == 0 { fromunitdata = unitsselectionviewcontroller.selectedunit buttontoset = frombutton } else { tounitdata = unitsselectionviewcontroller.selectedunit buttontoset = tobutton } setbuttontext(buttontoset, firstline: unitsselectionviewcontroller.selectedunit.unitcode, secondline: unitsselectionviewcontroller.selectedunit.unitname, firstlinefontsize: 15, secondlinefontsize: 11) } }
here's code use close second uiview:
func tableview(tableview: uitableview, willselectrowatindexpath indexpath: nsindexpath) -> nsindexpath? { selectedunit = temperatures[indexpath.row] self.navigationcontroller?.popviewcontrolleranimated(true) return indexpath }
the unwind code execute when tap done. nothing happens when select item in table.
any advice?
thanks
you can create unwind segue entire view controller. drag segue view controller objet exit object.
after segue created listed in document outline.
select , give identifier in attributes inspector. inside code when when tableview selects cell perform segue other normal segue.
override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let title = tableview.cellforrowatindexpath(indexpath)?.textlabel?.text performseguewithidentifier("backtoviewcontroller1", sender: title) }
then override prepareforsegue
method pass data first view controller.
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if let identifier = segue.identifier identifier == "backtoviewcontroller1", let destination = segue.destinationviewcontroller as? viewcontroller, selectedtitle = sender as? string { destination.selectedcountrytitle = selectedtitle } }
Comments
Post a Comment