別のクラスから @selector メソッドを呼び出すことは可能ですか? たとえば、「bannerTapped:」メソッドを作成し、「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 {
//do something here
}
更新:
viewController.m:
#import "anotherClass.h"
+(viewcontroller *)myMethod{
// some code...
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 {
//do something here
}