IOS Block Interface Reverse Pass value

Source: Internet
Author: User

In the previous blog "Introduction to iOS block", focusing on the concept of iOS block, this article will focus on their application in the development.

Block is an extension of the C language introduced by ios4.0+ and Mac OS X 10.6+ to implement the features of anonymous functions.
In the words of Wikipedia, block is an attribute added by Apple Inc. for C, C + +, and objective-c, allowing these languages to create closures using the syntax of a class lambda expression. With regard to closures, one sentence is simple and straightforward: closures are functions that can read other functions ' internal variables.

In iOS development, block has many uses, and the interface reverse value is one of them.

If we have a demand as follows: interface A has a button, a label. From interface a jump to interface B, enter the string in the input box of interface B and display it on the label of interface A. This is a typical example of a reverse value. The core of this example is: "Enter the string in the input box of interface B and display it on the label on interface A." The block implements the reverse pass value.

1. Declare the Block property in the. h file of the second view controller:

// Define block void (^nextviewcontrollerblock) (NSString *tftext);

@interface*Inputtf; @end-(ibaction) Btnaction: (ID) sender {        // determine if block is empty     If  (self. Nextviewcontrollerblock) {self        . Nextviewcontrollerblock (Self.inputTF.text);            }        [Self.navigationcontroller Popviewcontrolleranimated:yes];}

2. Get the second view controller in the first view and invoke the defined properties with the second view controller:

@interface*Nextvcinfolabel; @end

-(Ibaction) btnclicked: (ID) sender {        *NEXTVC = [[Nextviewcontroller alloc]init];     = ^ (NSString *tftext) {        = tftext;    };        [Self.navigationcontroller PUSHVIEWCONTROLLER:NEXTVC animated:yes];}

Effect

As this article is using Xib, omitted some UI details, attached to the code of this article link: source.

Where to write bad, hope to comment on the guidance. thanked ~

IOS Block Interface Reverse 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.