Is it possible to call @selector methods from another class? for example, I make the method "bannerTapped:" and call it from the class "myViewController.m".
myviewcontroller.m:
anotherClass *ac= [[anotherClass alloc]init];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:@selector(bannerTapped:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
cell.conversationImageView.tag = indexPath.row;
[cell.conversationImageView addGestureRecognizer:singleTap];
[cell.conversationImageView setUserInteractionEnabled:YES];
anotherClass.m:
-(void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
}
updated :
viewController.m:
#import "anotherClass.h"
+(viewcontroller *)myMethod{
anotherClass *ac= [[anotherClass alloc]init];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:@selector(bannerTapped:)];
}
anotherClass.h:
-(void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer;
anotherClass.m:
-(void)Viewdidload{
[viewController myMethod];
}
-(void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
}
source
share