Blocks are the answer to this problem:
Class B
@property (copy, nonatomic) void (^myBlock)(void);
-(id)initWithMyBlock:(void(^)(void))block
{
self = [super init];
if (self)
{
self.myBlock = block;
}
return self;
}
[btn addTarget:delegate action:@selector(btnPressed) forControlEvents:UIControlEventTouchUpInside];
- (void)btnPressed {
if (_myBlock) {
_myBlock();
}
}
Just watch out for retain cycles