IOS Block pass and attribute pass values

Source: Internet
Author: User

First Controller:

-(void) Baraction: (uibarbuttonitem*) Sender
{

Nextviewcontroller *next=[[nextviewcontroller Alloc]init];
Upload the value of the current page to the next page
next.stringvalue=self.rv.textfield.text;//Property Passing Value


Block Pass Value
__weak Rootviewcontroller *weakself=self;//weakself can be modified in the block, __week change the state of each other, to avoid release when not released


Block ahead, pass back.
next.pv=^{
return weakSelf.rv.textField.text;
//};



Block Pass Value
next.mb=^ (NSString *str) {
WEAKSELF.RV.TEXTFIELD.TEXT=STR;
};


[Self.navigationcontroller Pushviewcontroller:next Animated:yes];

}

A second controller:

. h file


typedef void (^myblock) (NSString *str);//block value, defines a block

typedef nsstring* (^passvalue) ();//block Front pass back

@interface Nextviewcontroller:uiviewcontroller

Accept the value passed from the previous page
@property (Nonatomic,strong) NSString *stringvalue;//Property Transfer value

Block Pass Value
@property (nonatomic,copy) myblock mb;//block Transfer value


@property (nonatomic,copy) passvalue Pv;//block Front pass behind

. m file

-(void) viewdidload
{
[Super Viewdidload];
Do any additional setup after loading the view.

Uibarbuttonitem *bar=[[uibarbuttonitem alloc]initwithtitle:@ "Back" Style:uibarbuttonitemstyledone target:self action: @selector (baraction:)];

Self.navigationitem.leftbarbuttonitem=bar;

Assign the value passed to the previous page to the current page.
self.nv.textfield.text=self.stringvalue;//Property Passing Value
Self.nv.textfield.text=self.pv;//block, back in front.

}

-(void) Baraction: (uibarbuttonitem*) Sender
{
SELF.MB (self.nv.textField.text);//block Pass Value

[Self.navigationcontroller Popviewcontrolleranimated:yes];

}

IOS Block pass and attribute pass values

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.