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 { ...
随机推荐
- 框架整合----------Hibernate、spring整合
说到整合框架,其实也就是环境的搭建了,首先我们要导包,这里连接数据库我们用到了spring容器,我们用连接池来进行数据库的连接,我们需要导入c3p0和jdbc的jar包,其余的就是spring和Hib ...
- 事件委托和JQ事件绑定总结
事件委托: 比喻:事件委托的事例在现实当中比比皆是.比如,有三个同事预计会在周一收到快递.为签收快递,有两种办法:一是三个人在公司门口等快递:二是委托给前台MM代为签收.现实当中,我们大都采用委托的方 ...
- 新一代Ajax API --fetch
之前 师傅跟我提过 一个新的Ajax API fetch 今天看到一篇关于fetch的文章,受益匪浅. XMLHttpRequest并不是专为Ajax而设计的,虽然各种框架对XHR的封装已经足够好用 ...
- hdu-5525 Product(费马小定理)
题目来源:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=644&pid=1003 前面用奇偶性约掉2, ...
- 学习 ---- JavaScript 高级设计程序 第三章(数据类型)
3.4 数据类型 基本数据类型:Undefined.Null.Boolean.Number.String 复杂数据类型:Object 3 ...
- Deep Learning 18:DBM的学习及练习_读论文“Deep Boltzmann Machines”的笔记
前言 论文“Deep Boltzmann Machines”是Geoffrey Hinton和他的大牛学生Ruslan Salakhutdinov在论文“Reducing the Dimensiona ...
- jQuery 移动端ajax请求列表数据,实现点击翻页效果(还有手势往下滑动翻页)。
1 首先是html部分 <div class="content"> <div class="list"></div> // ...
- 当shiro做成动态URL管理时出现循环注入BeanCurrentlyInCreationException的问题解决方法
<!-- Shiro的Web过滤器 --> <bean id="shiroFilter" class="org.apache.shiro.spring. ...
- 数据库DDL审计
一.为什么需要数据库DDL审计? DDL在生产系统中扮演非常重要的作用. 1)首先从业务角度来说,DDL可能意味着表结构变更,意味着新的版本即将发布,是个重要的时刻. 2)其次从运维角度来说,DDL尤 ...
- Rdseed与SAC的安装
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...