Objective-C之protocol协议
来源:互联网 发布:电影资源采集站源码 编辑:程序博客网 时间:2024/05/16 10:48
1 前言
@protocol是Objective-C中普遍存在的接口定义方式,即在一个类中通过@protocol定义接口,在另外类中实现接口,这种接口定义方式也成为“delegation”模式,@protocol声明了可以呗其他任何方法类实现的方法,协议仅仅是定义一个接口,而由其他的类去负责实现。
2 代码实例
main.m:
#import <Foundation/Foundation.h>#import "ClassWithProtocol.h"#import "TestAppDelegate.h"int main(int argc, const char * argv[]){ @autoreleasepool { ClassWithProtocol *another = [[ClassWithProtocol alloc] init]; TestAppDelegate *test =[[TestAppDelegate alloc] init]; //ClassWithProtocol的代理设置为TestAppDelegate another.delegate = test; //调用方法 [another processComplete]; [test release]; [another release]; } return 0;}
ClassWithProtocol.h:
#import <Foundation/Foundation.h>#import "ProcessDataDelegate.h"@interface ClassWithProtocol : NSObject{ id<ProcessDataDelegate> delegate;}//设置代理@property (retain)id delegate;-(void)processComplete;@end
运行结果:
2013-05-17 14:44:06.022 ProtocolTest[623:303] Process completed
3 结语
以上是所有内容,希望对大家有所帮助。
Demo代码实例:http://download.csdn.net/detail/u010013695/5397059
- Objective-C之protocol协议
- Objective-c 协议(protocol)
- Objective C 协议(Protocol)
- Objective-C 协议 protocol
- Objective-C中的协议Protocol
- Objective-C 协议(protocol)
- Objective-C 协议(protocol)
- Objective-C 协议(protocol)
- Objective-C 协议(protocol)
- Objective-C 协议(protocol)
- Objective-C 协议(protocol)
- Objective-c的协议protocol
- Objective-C 13 协议protocol
- iOS Objective-C之-1:协议Protocol
- [玩玩Objective-C]之协议(Protocol)
- objective-c中协议protocol的理解
- objective c学习:协议(protocol)
- objective-c中的正式协议 protocol
- 使用Joomla搭建网站(1)
- Android App之Email浅析
- 集合知识点总结02
- Android命令行启动程序-am命令的使用-纠正网上大部分资料的错误
- python Flask配置笔记
- Objective-C之protocol协议
- CSS3 @font-face
- 利用lipo命令编译合并百度地图API通用的静态类库
- ubuntu 更新时出现校验和不符的解决办法
- Common.Logging的输出配置
- NSString NSData char* 类型之间的转换
- 设置TableView分割线的风格和颜色
- Font-Awesome 魅力四射的html5 css3应用
- Android Studio打不开的问题