Protocol - 5
来源:互联网 发布:c语言开平方怎么写 编辑:程序博客网 时间:2024/04/29 10:39
在放一个关于委托协议传值的规范写法:
协议的定义:
#import <UIKit/UIKit.h>@class KeyBordView;@protocol KeyBordVIewDelegate <NSObject>- (void)beginRecord;- (void)finishRecord;- (void)KeyBordView:(KeyBordView* )keyBoardView textFiledBegin:(UITextField *)textFiled;- (void)KeyBordView:(KeyBordView* )keyBoardView textFiledReturn:(UITextField *)textFiled;@end
定义“委托者” delegate:
@interface KeyBordView : UIView@property (nonatomic, assign) id <KeyBordVIewDelegate> delegate;@end
在KeyBordView实现文件中的对委托方法的传值,这里传的是self,self.textFiled
注意到这里非常规范的先判断委托是否被赋予了(被委托者),具体是用respondsToSelector来判断,非常规范
#pragma mark - UITextField代理方法- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ if ([self.delegate respondsToSelector:@selector(KeyBordView:textFiledBegin:)]) { [self.delegate KeyBordView:self textFiledBegin:textField]; } return YES;}- (BOOL)textFieldShouldReturn:(UITextField *)textField{ if ([self.delegate respondsToSelector:@selector(KeyBordView:textFiledReturn:)]) { [self.delegate KeyBordView:self textFiledReturn:textField]; } return YES;}
最后是被委托者实现委托方法!
同理:
0 0
- Protocol - 5
- Protocol Buffers: (5) Protocol Buffer Basics: C++
- Philips RC-5 Protocol
- SOCKS Protocol Version 5
- Philips RC-5 Protocol
- Philips RC-5 Protocol
- Philips RC-5 Protocol
- rtsp protocol (5)
- Protocol
- protocol
- Protocol
- protocol
- @protocol
- Protocol
- Protocol
- protocol
- protocol
- protocol
- 欢迎使用CSDN-markdown编辑器
- java date20150819
- JAVA基本数据类型
- 日志处理(文件的读出和写入)
- 构造函数和析构函数的调用过程
- Protocol - 5
- LRU Cache
- 算术运算符
- 黑马程序员=====Java基础---继承、抽象、接口
- 初次安装Android Studio之环境设置
- [Leetcode]Kth Smallest Element in a BST
- JavaScript+CSS实现图片动态轮播dynamic_slider
- python函数之strip()
- 赋值运算符