IOS block, used as the callback function instead of the proxy, ios callback function

Source: Internet
Author: User

IOS block, used as the callback function instead of the proxy, ios callback function

Recently, I am working on a video conference project, but what I want to talk about today is basically irrelevant to the video. Let's create a button in a view and load this view in the controller.

When the button is clicked, the time response is passed to the controller for other modifications.

 

In this environment, we will soon think of using a proxy. Of course we can. Here we will not describe the proxy implementation process. We will use block to implement Code directly.

1 xxxx. h 2 @ interface xxxx: UIView 3 // The copy attribute of the block must be provided here. For details, refer to my article on block 4 @ property (nonatomic, copy) void (^ ButtonBlock) (BTNACTION); 5 @ end 6 7 8 xxxx. m 9 // here is the button click event 10-(void) menuAction :( UIButton *) btn11 {12 if (_ ButtonBlock) 13 14 _ ButtonBlock}

2. The connection to the controller is similar to the proxy.

1 xxxx = [[xxxx alloc] initWithFrame: callUseLocalView. frame]; 2 3 // _ weak _ typeof (self) weakSelf = self; 4 5 xxxx. buttonBlock = ^ (BTNACTION action // here I pass the struct. If you do not need to pass the parameter here, ignore it) {6 7 // here, when you execute the block, it will be called, if self is used here, pay attention to circular reference problem 8 };

Record a little bit every day to enrich yourself

By the way, the rent has risen again.

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.