0

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!!!");
}
Mike Zhu
  • 53
  • 5
  • 1
    make sure self.rightMeuViewController this is not nill before this line self.rightMeuViewController.delegate = self; – MOHAMMAD ISHAQ May 21 '15 at 10:43
  • where is rightMeuViewController intialise? – Aanabidden May 21 '15 at 10:43
  • the problem is you are not setting the delegate self.rightMeuViewController.delegate = self;// this will be nil, , how DiscoverTimelineTableViewController appears, it is in navigation or modal presented or another tab? – Raheel Sadiq May 21 '15 at 12:15
  • @RaheelSadiq Actually I use the library "SWRevealViewController" to make a side menu, and the rightMenuViewController is the side menu on the right hand side. – Mike Zhu May 22 '15 at 05:21

1 Answers1

0

Make sure that the delegate is properly set, i.e., self.rightMeuViewController should not be nil

it seems like you are not setting the rightMeuViewController property while navigating to second view controller

Saif
  • 2,678
  • 2
  • 22
  • 38