The simple wording of protocol

Source: Internet
Author: User

1 //2 //TouchView.h3 //Lessonuicontrolandsubclass4 5 6 7 #import<UIKit/UIKit.h>8 9 @classTouchView;Ten //1. Develop agreement, agreement name format: class name +delegate One @protocolTouchviewdelegate <NSObject> A  - @optional -- (void) Touchbegan: (TouchView *) TouchView; the- (void) touchmoved: (TouchView *) TouchView; -- (void) touchended: (TouchView *) TouchView; -- (void) touchcancelled: (TouchView *) TouchView; -  + @end -  + @interfaceTouchview:uiview A  at //2. Write attribute, property name delegate, type is ID, and abide by protocol < class name delegate> -@property (Assign, nonatomic)ID<TouchViewDelegate>Delegate; -  - @end
1 //2 //touchview.m3 //Lessonuicontrolandsubclass4 //5 6 #import "TouchView.h"7 8 @implementationTouchView9 Ten //3. Once the agent is found, let the agent do things One- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event { A     //determine if delegate has implemented a method -     if([_delegate respondstoselector: @selector (Touchbegan:)]) { - [_delegate touchbegan:self]; the     } - } -  -- (void) touchesmoved: (Nsset *) touches withevent: (Uievent *)Event { +     if([_delegate respondstoselector: @selector (touchmoved:)]) { - [_delegate touchmoved:self]; +     } A } at  -- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event { -     if([_delegate respondstoselector: @selector (touchended:)]) { - [_delegate touchended:self]; -     } - } in  -- (void) touchescancelled: (Nsset *) touches withevent: (Uievent *)Event { to     if([_delegate respondstoselector: @selector (touchcancelled:)]) { + [_delegate touchcancelled:self]; -     } the } *  $ @end

The simple wording of protocol

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.