I've a custom view subclass with UIView, in it, I've two buttons with an action, now I want to learn something good, and I don't want to implement a delegate to know which button tapped from other class.
I'm showing my custom view with this method,
CustomView *view = [[CustomView alloc] init];
[view show];
This will show my custom view, with two buttons inside (please assume everything is working fine, I only want to implement block to know which button have been tapped). ^_^
What I've tried for block,
- (void) showViewWithCompletionBlock:(void(^)(CustomViewType type))completion;
and yes, I would able to write like this,
CustomView *view = [[CustomView alloc] init];
[view showViewWithCompletionBlock:^(CustomViewType type) {
}];
but now here's the trouble, I don't know how to call this block (or how I can return CustomViewType) when button tap?
Those two buttons action is like this,
- (void) someAction:(UIButton *)sender {
//sender.tag is a CustomViewType which user choose
}
For a note, CustomViewType is an enum like this,
typedef enum {
CustomViewTypeOption1,
CustomViewTypeOption2,
}CustomViewType;