Target-action model of OBJECTIVE-C release solution

Source: Internet
Author: User

target-action Model of OBJECTIVE-C release solutionThe target-action pattern is the way the method calls between objects that are very common in OBJC, but OBJC calls the method call a send Message.

A bunch of situations can take advantage of this pattern when dealing with a variety of GUI events while interacting with the UI. The processing mode corresponding to. NET is delegate/event. However, target-action the C language, is more flexible, compile time without any checks, are run-time binding . Look at the code

Uibarbuttonitem *savebtn = [[Uibarbuttonitem alloc] initwithtitle:@ "Save" Style:uibarbuttonitemstyledone target: Self action: @selector (saverecipe:)];

The implementation of a Button control's Click event. Here, the button is pressed to invoke the Saverecipe method on target (that is, self). According to OBJC's custom, when the Click event occurs, a message is sent to the self object that causes a call to the Saverecipe method on the Self object.

How's that, very flexible? There is no pre-defined interface for the template to restrict the signature of the target invocation method. More flexible is that the target method name can be generated at run time. Like what


[Button setaction:nsselectorfromstring ([TextField stringvalue]);

Of course, the shortcomings are obvious, there is no compile-time check, if the target object does not have a corresponding method, it can only wait until the runtime to find.

Target-action model of OBJECTIVE-C release solution

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.