Value passing between iOS pages: One-case value passing, block Value passing, and iosblock

Source: Internet
Author: User

Value passing between iOS pages: One-case value passing, block Value passing, and iosblock

There are a lot of values passed between ios pages. The front side has already shared the attribute transfer value and the proxy transfer value. Today we mainly talk about the single-case transfer value and block transfer value.

Single case transfer value: Singleton mode is a common development mode. Singleton is obtained from the same object no matter when the object is initialized in the entire program, objects have the same attributes, so they can be used to pass values.

 

The block value is similar to the proxy value. It is mainly used to pass the value to the first page on the second page. The specific steps for transferring the block value are as follows:

 

On the second page:

1. Declaration: block typedef void (^ SendMessagerBlock) (NSString * str );

2. Creation Method:-(void) sendMessage :( SendMessagerBlock) block;

3. Declare attributes: @ property (nonatomic, copy) SendMessagerBlock;

4. Implementation Method:-(void) sendMessage :( SendMessagerBlock) block {
Self. block = block;
}

5. Call block: self. block (self. textField. text );

On the first page

6. Call method: [seconVC sendMessage: ^ (NSString * str ){
WeakSelf. textField. text = str;
}];

Related Article

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.