Runtime_消息转发机制
来源:互联网 发布:手机美工软件哪个更好 编辑:程序博客网 时间:2024/05/17 21:48
demo下载地址 http://download.csdn.net/detail/xlsn0w/9429193
#import "Person.h"
#import <objc/objc-runtime.h>
#import "Cat.h"
@implementation Person
/**
* 在ViewController里面调用catchMouse而Person没有catchMouse
但发现Cat拥有catchMouse方法可以在外界调用Person类的catchMouse方法转发消息给Cat
*/
{
Cat *cat;
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
NSMethodSignature *methodSignature = [supermethodSignatureForSelector:aSelector];
if (methodSignature == nil) {
cat = [Catnew];
methodSignature = [cat methodSignatureForSelector:aSelector];
}
return methodSignature;
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
[anInvocation invokeWithTarget:cat];
}
在
ViewController.m里面实现人的方法具有猫的抓老鼠方法
#import "Person.h"
#import <objc/objc-runtime.h>
#import "Cat.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Person *person = [Personnew];
[person performSelector:@selector(catchMouse)];
}
- Runtime_消息转发机制
- IOS消息转发机制
- oc消息转发机制
- iOS消息转发机制
- OC-消息转发机制
- ios消息转发机制
- oc消息转发机制
- IOS 消息转发机制
- iOS消息转发机制
- 消息转发机制
- iOS消息转发机制
- OC消息转发机制
- 消息转发机制
- oc消息转发机制
- Runtime消息转发机制
- OC消息转发机制
- iosiOS消息转发机制
- Runtime消息转发机制
- poj 3744 Scout YYF I 矩阵快速幂 概率论
- 【JAVA】1、准备工作——安装JDK与配置环境变量path
- jQuery的deferred对象详解
- vxWorks的计数信号量和看门狗定时器联合使用的示例
- UIDynamic物理引擎
- Runtime_消息转发机制
- 使用拦截器或者AOP实现权限管理(OA系统中实现权限控制)
- 第一章:一个简单的Web服务器
- 《Python for kids》学习笔记(五)
- Web Service Jaxws注解、CXF注解和发布
- Hello CSDN!
- vxWorks互斥信号量示例
- BestCoder Round #71 (div.2) 1002KK's Point
- java基础练习 特殊的数字