#import<UIKit/UIKit.h>typedefvoid(^myblock) (nsstring*);@interfaceSecondviewcontroller:uiviewcontroller@property (retain,nonatomic) Uitextfield*MyTextField; @property (copy,nonatomic) Myblock block;-(secondviewcontroller*) Initwithblock: (myblock) block;@end#import "SecondViewController.h"@interfaceSecondviewcontroller ()@end@implementationSecondviewcontroller-(Secondviewcontroller *) Initwithblock: (myblock) block{if(self=[Super Init]) {Self.block=Block; } returnSelf ;}- (void) viewdidload {[Super viewdidload]; UIButton* btntest=[UIButton Buttonwithtype:uibuttontyperoundedrect]; Btntest.frame=cgrectmake ( -, the, the, -) ; [Btntest settitle:@"Test"Forstate:uicontrolstatenormal]; [Btntest addtarget:self Action: @selector (back) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:btntest]; Uitextfield* Textfield=[[uitextfield Alloc]initwithframe:cgrectmake ( -, the, the, -)]; Textfield.borderstyle=Uitextborderstyleroundedrect; [Self.view Addsubview:textfield]; Self.mytextfield=TextField;}-(void) back{if(Self.block) {self.block (self.myTextField.text); } [Self.navigationcontroller Poptorootviewcontrolleranimated:yes];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}/*#pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before n avigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [s] Egue Destinationviewcontroller]. Pass the selected object to the new view controller.}*/@end#import "ViewController.h"#import "SecondViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Uibarbuttonitem* Btnname=[[uibarbuttonitem Alloc]initwithtitle:@"Next"Style:uibarbuttonitemstyledone target:self Action: @selector (next)]; Self.navigationItem.rightBarButtonItem=Btnname; //additional setup after loading the view, typically from a nib.}-(void) next{Secondviewcontroller* Secondvc=[[secondviewcontroller alloc]initwithblock:^ (nsstring*str) {NSLog (@"%@", str); Self.title=str; }]; [Self.navigationcontroller PUSHVIEWCONTROLLER:SECONDVC animated:yes];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
IOS code block Pass Value