Have you tried using the ReactiveCocoa framework and adding some blocks for your code, this is not the easiest approach, but I would say that it is most effective when you have several dependencies and is very useful for scaling
I created a small project to solve your problem using my proposed approach (I tried to adapt it to the old old MVC model instead of my preferred MVVM)
you can find it here
https://github.com/MWaly/MWButtonExamples
be sure to install the cocoa pods file, since we need “ReactiveCocoa” and “BlocksKit” for this sample
we will use two main classes
ViewController => A viewController object that displays the MWCustomButton buttons => Custom UIButton that handles events
when creating buttons, a weak link to the viewController is also created using the property
@property (weak) ViewController *ownerViewController ;
events will be processed using the blocksKit bk_addEventHandler method and pass it to the ViewController (selectedButtonCallBackBlock)
[button bk_addEventHandler:^(id sender) { self.selectedButtonCallBackBlock(button); } forControlEvents:UIControlEventTouchUpInside];
now in the ViewController for each button pressed, callBackButtonBlock will be a trigger, where it will change the currently selected button, if applicable
__weak __typeof__(self) weakSelf = self; self.selectedButtonCallBackBlock=^(MWCustomButton* button){ __typeof__(self) strongSelf = weakSelf; strongSelf.currentSelectedButton=button; };
in the MWCustomButton class, he will listen for any changes in the "currentSelectedButton" property of his owner ViewController and will change his selection property to match it using our good Reactive cocoa
///Observing changes to the selected button [[RACObserve(self, ownerViewController.currentSelectedButton) distinctUntilChanged] subscribeNext:^(MWCustomButton *x) { self.selected=(self==x); }];
I think this will solve your problem, again your question can be solved in a simpler way, however I believe that using this approach would be more scalable and cleaner.