storyboard - How to Pass information Back in iOS when reversing a Segue using Swift? -
i have 2 view controllers, 1 , two. go vc 1 vc two. on vc two, select info store in array. when press "back" button on navigation bar, send array vc one.
what's best way using swift & storyboards?
thanks!
if presenting modal view done , cancel buttons (sort of picker), grabbing value during unwind segue method easiest.
given want utilize navigation controller's native button, best practice implement protocol vc 1 can conform to, , update vc 1 info on vc 2 selected. like:
in vctwo.swift:
protocol vctwodelegate { func updatedata(data: string) } class vctwo : uiviewcontroller { var delegate: vctwodelegate? ... @ibaction func choicemade(sender: anyobject) { // things self.delegate?.updatedata(self.data) } ... } and in vcone.swift:
class vcone: viewcontroller { ... override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if segue.identifier == "vctwosegue" { (segue.destinationviewcontroller vctwo).delegate = self } } ... } extension vcone: vctwodelegate { func updatedata(data: string) { self.internaldata = info } } storyboard swift ios8
No comments:
Post a Comment