IOS开发 Target-Action方法的实现

1.创建一个类继承UIView

2.初始化方法使用:

- (id)initWithTarget:(id)aTarget action:(SEL)aAction
{
    self = [super init];
    if (self == nil) {
        _target= aTarget;
        _action = aAction;
    }
    return self;
}
3.在touchesBegan中实现目标方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [_target performSelector:_action withObject:self];
}


你可能感兴趣的:(ios开发,Target-Action方法)