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 { ...
随机推荐
- JavaScript继承
最佳的继承范式 寄生组合继承 我们来看一下它的实现方式: function Object(o){ var TempObject = function(){}; TempObject.prototype ...
- LMAX Disruptor—多生产者多消费者中,消息复制分发的高性能实现
解决的问题 当我们有多个消息的生产者线程,一个消费者线程时,他们之间如何进行高并发.线程安全的协调? 很简单,用一个队列. 当我们有多个消息的生产者线程,多个消费者线程,并且每一条消息需要被所有的消费 ...
- python成长之路【第十七篇】:玩转jQuery
一.jQuery简介 1.1.jQuery是什么 jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. jQuery是继prototy ...
- java时间段分成小段存储
package testThread; import java.text.ParseException; import java.text.SimpleDateFormat; import java. ...
- malloc error:初始值设定元素不是常量
#include <stdio.h> #include <stdlib.h> char *buf = (char *)malloc(BUFSIZ); setbuf(stdout ...
- 使用automake等命令自动生成Makefile文件 (转载)
使用automake等命令自动生成Makefile文件 Linux下编程时,为了方便编译,往往使用Makefile文件自动完成编译,但是Makefile文件本身的书写十分复杂,规则很多.好在Lin ...
- Eclipse WTP Tomcat hot deploy
转自: http://ducquoc.wordpress.com/2010/11/06/eclipse-wtp-tomcat-hot-deploy/ One of the reasons why Ja ...
- ios 常用字符串的操作
//将NSData转化为NSString NSString* str = [[NSString alloc] initWithData:response encoding:NSUTF8S ...
- JVM垃圾回收机制总结:调优方法
转载: JVM垃圾回收机制总结:调优方法 JVM 优化经验总结 JVM 垃圾回收器工作原理及使用实例介绍
- Myeclipse的使用
一,错误解决 1, 现象:使用eclipse运行带有main函数的Java文件时,出现editor does not contain a main type的错误框 原因:原来这个class所在包没有 ...