aftab muhammed khan aftab muhammed khan - 8 months ago 44
iOS Question

How to call Delegate method as a selector in same delegate class

I have my custom delegate class for


Currently i am facing issue in my

i have to define
for each BarItem.

So Far
i define selector for each bar item like this:

SEL selector = (menu == MyMenu) ? @selector(leftSelected:) : @selector(rightSelected:);

the are working perfect because they are local method in my delegate class so there is no problem.

but one point i need to declare my delegate method as @Selector because its define in other viewcontroller.

here i have to define my delegate method as selector.

SEL selector = (menu == MenuLeft) ? @selector(leftMenuSelected:) : @selector(righttMenuSelected:);

if (menu == MenuTwo) {
selector = @selector(arrowMenuSelectedOut);

if ( menu == MenuTwo ){

UIImage *image = [UIImage imageNamed:MENU_ARROW];

UIBarButtonItem *btn= [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:selector];
btn.imageInsets = UIEdgeInsetsMake(0, 0, 0, -25.0);

return btn;

UIImage *image = [UIImage imageNamed:MENU_IMAGE];

return [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:selector];

this is my delegate method.

@protocol myNavigationViewControllerDeleget<NSObject>
- (void)arrowMenuSelectedOut;

which is placed in other viewcontroller.

- (void)arrowMenuSelectedOut

NSLog(@"button press");


i want to use this arrowMenuSelectedOut method as selector from same delegate class on button press.

Answer Source

if you like to call delegate try it like this.

[self.mydelegate arrowMenuSelectedOut];

or in you case

UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self.mydelegate action:@selector(arrowMenuSelectedOut)];

also check did you define you delegate properly it should not be nil. try this