OC7_代理的基本概念
2015-06-24 20:09
302 查看
// // Cat.h // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> @interface Cat : NSObject - (void)bark; @end // // Cat.m // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "Cat.h" @implementation Cat - (void)bark { NSLog(@"Miao miao miao ..."); } @end // // Dog.h // OC7_代理 的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> @interface Dog : NSObject - (void)bark; @end // // Dog.m // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "Dog.h" @implementation Dog - (void)bark { NSLog(@"Wang wang wang ..."); } @end // // Person.h // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> @interface Person : NSObject { id _delegate; } @property (retain,nonatomic)id delegate; - (void)go; @end // // Person.m // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "Person.h" #import "Dog.h" #import "Cat.h" @implementation Person - (void)go { [_delegate bark]; } //- (void)dealloc //{ // [_delegate release]; // [super dealloc]; //} @end
// // main.m // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> #import "Person.h" #import "Dog.h" #import "Cat.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //NSLog(@"Hello, World!"); Person *xiaoXin = [[Person alloc] init]; Dog *dog = [[Dog alloc] init]; xiaoXin.delegate = dog; [xiaoXin go]; Cat *cat = [[Cat alloc] init]; xiaoXin.delegate =cat; [xiaoXin go]; } return 0; }
相关文章推荐
- setContentView( )方法
- 编程之美
- java——获取一个应用程序运行的次数,如果超过5次,给出使用次数已到请注册的提示,并不要再运行程序
- urlurl
- 我的第一个博客
- 07-排序2. Insert or Merge (25)
- 第1章 游戏之乐——让CPU占用率曲线听你指挥
- LeetCode:Same Tree
- android---xml---include用法(导入另一个XML文件到本布局中)
- 由普利姆算法想到一个游戏之后
- nsurl
- Windows live Writer博客园,51CTO,网易博客,新浪博客配置方法
- xml解析与保存
- Tomcat 系统架构与设计模式,第 1 部分: 工作原理图 1.Tomcat 的总体结构
- 大型商贸系统(进货管理)技术解析(二)自营进仓单录入
- MFC对话框应用程序添加自定义消息
- Minimum Depth of Binary Tree
- DHCP服务器搭建与管理
- Linux下select应用
- Linux系统编程——vfork() 函数详解