首页 > 其他 > 详细

target action

时间:2014-09-05 03:21:51      阅读:311      评论:0      收藏:0      [点我收藏+]

//为当前视图指定当视图接收到响应事件之后,由target来通过action方法进行响应.

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    //用实例变量存储外界传入的参数,方便在其他方法中使用
    _target = target;
    _action = action;
    _controlEvents = controlEvents;
    NSLog(@"%@",_target);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(UIControlEventTouchDown == _controlEvents)
    {
    //当当前视图接收到触摸事件之后,交由target去处理.
    [_target performSelector:_action withObject:self];
        
    }
    
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (UIControlEventTouchUpInside == _controlEvents) {
        [_target performSelector:_action withObject:self];
    }
}

target action

原文:http://qccccc.blog.51cto.com/6004423/1548914

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!