IOS code block Pass Value

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.