aviewcontroller.h@interface aviewcontroller : uiviewcontroller { uilabel *valuelabel;//. To receive the value returned by the Secondviewcontroller} @end implement aviewcontroller.m- (void) viewdidload{ [super viewdidload]; valuelabel = [[uilabel alloc ] initwithframe:cgrectmake (10, 100, 300, 50)]; [self.view Addsubview:valuelabel]; uibarbuttonitem *nextbtn = [[uibarbuttonitem alloc] initwithtitle:@ "Next" style:uibarbuttonitemstyleplain target:self action: @selector (NextClick )]; self.navigationitem.rightbarbuttonitem = nextbtn;} - (void) Nextclick{ bviewcontroller *svc = [[bviewcontroller alloc] init]; svc.backvalue = ^ (Nsstring *strvalue) {//set the Block property of Secondviewcontroller Edge, which is the key of this program valueLabel.text = strValue;}; [self.navigationcontroller pushviewcontroller:svc animated:yes];} bviewcontroller.h@interface bviewcontroller : uiviewcontroller@property (nonatomic, copy) void (^backvalue) (Nsstring *strvalue), @property (nonatomic, retain) uitextfield *text; @end implement bviewcontroller.m@implementation bviewcontroller- (void) viewDidLoad{ [super viewdidload]; self.view.backgroundcolor = [UIColor whiteColor]; text = [[UITextField alloc] Initwithframe:cgrectmake (10, 50, 300, 40)]; text.borderstyle = UITextBorderStyleRoundedRect; [self.view addSubview:text]; uibutton *btn = [uibutton buttonwithtype:uibuttontyperoundedrect]; Btn.frame = cgrectmake (10, 110, 60, 30); [btn settitle:@ " Back to " forstate:uicontrolstatenormal]; [btn addtarget:self action: @selector (Btnclick) forcontrolevents:uicontroleventtouchupinside]; [self.view  ADDSUBVIEW:BTN];} - (void) btnclick{self.backvalue (self.text.text);//Tune block Law [self.navigationcontroller Popviewcontrolleranimated:yes];} @end
The idea of the block passing value:
1, a class to pass a value, that is, to establish the Block property void (^backvalue) (nsstring *strvalue), and then implement it: Self.backvalue (the value to pass )
2, Class B to get the value of a is to achieve the properties of a.
Aviewcontroller *AVC = [[Aviewcontroller alloc] init]; By block value, city switch avc.backvalue = ^ (NSString *strvalue) {//Set Secondviewcontroller? Side of the Block property, which is the key to this program Self.citynam e = strvalue; };
3, parsing the Blcok attribute
Return value-Name-parameter
Return value-name-equals sign
@property (nonatomic, copy) void (^backvalue) (NSString *strvalue); @property (nonatomic, copy) NSString *name; =
IOS block use