Basically, I have two UIViewControllers, there are some buttons in one of them. Once the user touches the button in one of the View Controllers, I want to trigger some actions in another view controller. But it seems not working somehow. Basically, the "if" condition which is:
if (self.delegate && [self.delegate respondsToSelector:@selector(userDidTouchButtons:)])
{
[self.delegate userDidTouchButtons:self];
}
seems not working, because the [self.delegate respondToSelector]
is always false.
This is the .h file of the first view controller, which has some buttons. #import
@class RightSideMenuViewController;
@protocol RightSideMenuDelegate <NSObject>
- (void) userDidTouchButtons: (RightSideMenuViewController *) rightMenuViewController;
@end
@interface RightSideMenuViewController : UIViewController
@property (nonatomic, assign) id <RightSideMenuDelegate> delegate;
@end
This is the .m file of the first view controller.
- (IBAction)badmintonClicked:(UIButton *)sender
{
if (self.delegate && [self.delegate respondsToSelector:@selector(userDidTouchButtons:)])
{
[self.delegate userDidTouchButtons:self];
}
}
This is the .m file of the second view controller, where I want to trigger the action here, according to the buttons in the first view controller.
#import "RightSideMenuViewController.h"
@interface DiscoverTimelineTableViewController () <RightSideMenuDelegate>
@property (strong, nonatomic) RightSideMenuViewController *rightMeuViewController;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.rightMeuViewController.delegate = self;
}
#pragma mark - RIGHT MENU Delegate methods
- (void) userDidTouchButtons: (RightSideMenuViewController *) rightMenuViewController
{
NSLog(@"He touches me!!!");
}