NSInvocation 回调使用

声明
NSInvocation* m_touchDown;


赋值
-(void) setTouchMoveCallback:(id) target sel:(SEL) sel {
    if (m_touchMove) {
        [m_touchMove release];
        m_touchMove = nil;
    }
    NSMethodSignature *sig= [target methodSignatureForSelector:sel];
    NSAssert(sig, @"");
    m_touchMove = [NSInvocation invocationWithMethodSignature:sig];
    [m_touchMove setTarget:target];
    [m_touchMove setSelector:sel];
    [m_touchMove setArgument:&self atIndex:2];
    [m_touchMove retain];
}


开始回调
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (m_touchDown) {
        [m_touchDown setArgument:&touch atIndex:3];
        [m_touchDown setArgument:&event atIndex:4];
        [m_touchDown invoke];
    }
    return YES;
}


使用
[btn setTouchDownCallback:self sel:@selector(eventTouchBegin:touch:event:)];


回调函数

-(void) eventTouchBegin:(myButton*) sender touch:(UITouch*) touch event:(UIEvent*) event {
   // TODO
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值