Requirements: Use the proxy to achieve the Echo value (the following example uses the button in the second view controller to change the contents of the label in the first view controller)
First, create Rootviewcontroller
Import Foundationimport Uikitclass rootviewcontroller:uiviewcontroller,changeworddelegate{var qzLabel:UILabel? Override Func Viewdidload () {super.viewdidload () Self.title = "Rootviewcontroller" Let Rightbtn:uibar Buttonitem = Uibarbuttonitem (title: "Next Page", Style:.) Plain,target:self,action: "NextPage") Self.navigationItem.rightBarButtonItem = rightbtn let rect = CG Rect (x:0,y:200,width:320,height:50) Qzlabel = UILabel (frame:rect) qzlabel!. Text = "Qin Zhiwei" qzlabel!. TextAlignment = Nstextalignment.center Self.view.addSubview (qzlabel)} func nextPage () { Let svc = Secondviewcontroller () svc.delegate = self Self.navigationController.pushViewController (svc,anim ated:true)} func Changeword (controller:secondviewcontroller,string:string) {qzlabel!. Text = String println ("Qzlabel.text = = \ (String)")}}
Ii. creation of Secondviewcontroller
Import foundationimport uikit//Definition Protocol change label Content protocol changeworddelegate:nsobjectprotocol{//callback method func Changeword (Con troller:secondviewcontroller,string:string)}class secondviewcontroller:uiviewcontroller{var temp = 0 Var Delegate:C Hangeworddelegate? Override Func Viewdidload () {super.viewdidload () Self.title = "Secondviewcontroller" self.view.backgr Oundcolor = Uicolor.greencolor () Let rect = CGRect (x:50,y:200,width:150,height:50) var MyButton = UIButton (f Rame:rect) Mybutton.center = Cgpointmake (160,200) mybutton.settitle ("Change label contents", Forstate:. Normal) Mybutton.addtarget (self,action: "btnclicked", forControlEvents:. Touchupinside) Self.view.addSubview (MyButton)} func btnclicked () {temp++ println ("I was clicked The ") if (delegate) {delegate?. Changeword (self,string: "Qin Zhiwei" +string (temp))}}}
Swift language implements proxy value