protocol的简单写法
//
// TouchView.h
// LessonUIControlAndSubClass #import <UIKit/UIKit.h> @class TouchView;
//1.制定协议,协议名字格式:类名+Delegate
@protocol TouchViewDelegate <NSObject> @optional
- (void)touchBegan:(TouchView *)touchView;
- (void)touchMoved:(TouchView *)touchView;
- (void)touchEnded:(TouchView *)touchView;
- (void)touchCancelled:(TouchView *)touchView; @end @interface TouchView : UIView //2.写属性,属性名delegate,类型是id,并且要遵守协议<类名Delegate>
@property (assign, nonatomic) id<TouchViewDelegate> delegate; @end
//
// TouchView.m
// LessonUIControlAndSubClass
// #import "TouchView.h" @implementation TouchView //3.一旦找到代理,让代理执行事情
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//判断delegate是否实现了某方法
if ([_delegate respondsToSelector:@selector(touchBegan:)]) {
[_delegate touchBegan:self];
}
} - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if ([_delegate respondsToSelector:@selector(touchMoved:)]) {
[_delegate touchMoved:self];
}
} - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([_delegate respondsToSelector:@selector(touchEnded:)]) {
[_delegate touchEnded:self];
}
} - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
if ([_delegate respondsToSelector:@selector(touchCancelled:)]) {
[_delegate touchCancelled:self];
}
} @end
protocol的简单写法的更多相关文章
- 使用Ext.Net时,配置文件的最简单写法
使用Ext.Net时,配置文件的最简单写法 <?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配 ...
- html5滚动页面简单写法
html5滚动页面简单写法纵向滚动比较简单 直接在外面加个高度 然后overflow-y: auto; 横向比较复杂了外面写两层 最外面一层写个宽度 overflow-x: auto;第二层 写wid ...
- TFTP(Trivial File Transfer Protocol,简单文件传输协议)
TFTP(Trivial File Transfer Protocol,简单文件传输协议),是 TCP/IP 协议族中用来在客户机和服务器之间进行简单文件传输的协议,开销很小.这时候有人可能会纳闷,既 ...
- PHP去重的简单写法
PHP去重的简单写法用array_flip实现去重效果 <pre><?php$arr =array("a"=>"a1","b& ...
- Google Protocol Buffer 简单介绍
以下内容主要整理自官方文档. 为什么使用 Protocol Buffers .proto文件 Protocol Buffers 语法 编译.proto文件 Protocol Buffers API 枚 ...
- linux IPC socket(3)server简单写法
写server的一些流程总结 一.向内核申请一个socket TCP形式 sock_fd = socket(AF_INET, SOCK_STREAM, ); UDP形式 sfd = socket(AF ...
- foreach循环的简单写法
简单的foreach循环写法: pickedItems.ForEach(item => { this.List.Remove(item); }); //注意,List 必须和pickedItem ...
- javascript模块简单写法
写法1: (function (wd, doc) { var mw = {}; mw.noConflict = noConflict; var _$ = wd.$; wd.$ = mw; functi ...
- WPF之Binding的三种简单写法
环境 类代码 public class Person:INotifyPropertyChanged { private string name; public string Name { get { ...
随机推荐
- Linux服务器的那些性能参数指标
Linux服务器的那些性能参数指标 一个基于Linux操作系统的服务器运行的同时,也会表征出各种各样参数信息.通常来说运维人员.系统管理员会对这些数据会极为敏感,但是这些参数对于开发者来说也十分重要, ...
- Oracle Forms 10g Tutorial Ebook Download - Oracle Forms Blog
A step by step tutorial for Oracle Forms 10g development. This guide is helpful for freshers in Orac ...
- css属性的选择对动画性能的影响
现在手机的占比越来越高,各种酷炫页面层出不穷,这些特效都离不开css动画.说到css动画,主流的情况也就无非这两大类:位移和形变.而我们在写一个动画特效的过程中,如何去提升它的性能呢?当然首先我们需要 ...
- codeforces 85D D. Sum of Medians 线段树
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
- python走起之第十三话
前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多人觉得,堡垒机就是跳板机,其实这个认识是不全面的,跳板功能只是堡垒机所具备的功能属性中的其中 ...
- codeigniter nginx配置
转载:http://www.nginx.cn/1134.html server{ listen 80; server_name www.ci.oa.com; access_log /usr/local ...
- DBUTIL 调用存储过程例子
执行存储过程和执行select查询相比,无非就是SQL语句不同.下面是一个用存储过程查记录的例子.根据你的数据库不同和域对象不同,此代码要修改 Java code ? 1 2 3 4 5 Quer ...
- PHP获取当前时间戳,当前时间、及解决时区问题
一.获取当前时间戳 方法1:通过time函数 time(); 方法2:通过$_SERVER中的REQUEST_TIME元素 $_SERVER['REQUEST_TIME']; 方法3:通过strtot ...
- Apache Commons Lang
http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/package- ...
- SpringMVC+Mybatis+Spring整合
Maven引入需要的JAR包 pom.xml <properties> <!-- spring版本号 --> <spring.version>4.0.2.RELEA ...