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 { ...
随机推荐
- iOS全军覆没!分分钟教你徒手破解iPhone
http://iphone.tgbus.com/news/class/201503/20150304141407.shtml 破解id密码的最新dns 218.59.181.182
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 函数式functor的理解
// 参考 // http://jiyinyiyong.github.io/monads-in-pictures/ // https://llh911001.gitbooks.io/mostly-ad ...
- hdu-5525 Product(费马小定理)
题目来源:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=644&pid=1003 前面用奇偶性约掉2, ...
- Maven打包程序
1.src/main目录下建立scritps.config.assembly目录 scritps:存放脚本文件如批处理 assembly:打包配置文件 2.assembly目录下建立package ...
- OpenCV 计算区域的内部参数
对于一个区域,怎么进一步针对区域内部特征进行处理呢 ? 首先,我们要提取出来内部的某些特征才能说话,下面提取一些简单的特征,话不多说见代码: 1.平均数及方差参数: Mat tempMean, tem ...
- SAP公司间采购订单关联交货单报表源代码(自己收藏)
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF } ...
- BIND的进阶二:视图,日志,转发,子域的授权
实验分为4部分组成: 1:DNS的转发 2:DNS日志 3:子域的授权 4:智能DNS的简单配置根据网段来分配不同的ip地址 一:DNS的转发: 转发方式有两种:only (直接把客户端请 ...
- Java开发常用的在线工具
原文出处: hollischuang(@Hollis_Chuang) 作为一个Java开发人员,经常要和各种各样的工具打交道,除了我们常用的IDE工具以外,其实还有很多工具是我们在日常开发及学习过程中 ...
- cin, cin.getline等函数
char s[100]; cin>>s; // 输入一个字符串,遇“空格”.“TAB”.“回车”都结束 cin.getline(s, 20); // cin.get( ...