Block implementation agent/notification effect

Source: Internet
Author: User

Example 1: A controller-"jump-" B controller, false assumption from the B controller callback array to a controller

Implementation: B Controller. h file defines a block parameter,. m file execution block,a controller settings block content

B.h file
Create block blocks @property (nonatomic,copy) void (^block) (Nsarray *array);
B.M File//execute block block
!self.Block? (Space here): Blcok (array); To determine if a block exists, the block is executed, and an array of arrays is passed to xxx (who defines the execution code for block blocks, which is passed to a controller)

a.m. File
B *b=[[b Alloc]init];
b.block=^ (Nsarray *array){
Block execution Code
//...
};
B.M in the presence of block blocks, the executionblcok (array) , and entered the A.M. "Block Execution Code "Processing, where"Block execution Code" OfArrayParameter gets the array b.m passed over

Using the block procedure, be aware of circular references, such as a circular reference to self, using the __weak typeof (self) weakself=self;

Example 2: A controller completes the task, notifies the B controller to perform the next task

A.h File//Creating block blocks@property (nonatomic,copy)void(^Block) (); a.m. File//Executing block blocks!self. Block? (Space here): Blcok ();//to determine if a block exists, the block is executedb.m file a*a=[[A Alloc]init];a.block=^() {//Block Execution Code//perform one-step tasks};//a block block is determined in the A.M., Execution Blcok (), b.m into "Block execution code" is equivalent to receive a pass over the notification signal//using the block procedure, be aware of circular references, such as a circular reference to self, using the __weak typeof (self) weakself=self;

Block implementation agent/notification effect

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.