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