swift - Moving Data Using Protocol delegates in Navigation controller -


i working on app need pass data throw navigation controller , back.
got work using tutorial: link

in app have first view controller(in tutorial uiviewcontroller) beside push segue secondviewcontroller(in tutorial footwovc) own view controller.

so question can use same protocol vc or need make protocol?

import uikit  class viewcontroller: uiviewcontroller,footwoviewcontrollerdelegate {     @iboutlet var colorlabel : uilabel!     override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.     }     func myvcdidfinish(controller: footwoviewcontroller, text: string) {         colorlabel.text = "the color " +  text         controller.navigationcontroller?.popviewcontrolleranimated(true)     }     override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) {         if segue.identifier == "mysegue"{             let vc = segue.destinationviewcontroller as! footwoviewcontroller             vc.colorstring = colorlabel.text!             vc.delegate = self         }     } } import uikit  protocol footwoviewcontrollerdelegate{     func myvcdidfinish(controller:footwoviewcontroller,text:string) }  class footwoviewcontroller: uiviewcontroller {     var delegate:footwoviewcontrollerdelegate? = nil     var colorstring:string = ""     @iboutlet var colorlabel : uilabel!      @ibaction func savecolor(sender : uibarbuttonitem) {         if (delegate != nil) {             delegate!.myvcdidfinish(self, text: colorlabel!.text!)         }     }      @ibaction func colorselectionbutton(sender: uibutton) {          colorlabel.text = sender.titlelabel!.text!     }      override func viewdidload() {         super.viewdidload()         // additional setup after loading view.         colorlabel.text = colorstring     } } 

after time figured out , wasn't hard after all.
needed change protocol to:

protocol footwoviewcontrollerdelegate{  func myvcdidfinish(controller:uiviewcontroller,text:string) } 

so can used other view controllers. , further had same code in third view controller.

i have question feel free ask.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -