为 UIGestureRecognizer 设置委托发出警告

Setting delegate for UIGestureRecognizer giving warning

为 UITapGesture 设置委托发出警告

这是我的代码:

UITapGestureRecognizer *tapOtherPlayers = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapcollectionViewOtherPlayers:)];
tapOtherPlayers.delegate = self;
[tapOtherPlayers setNumberOfTapsRequired:1];
[collectionViewOtherPlayers addGestureRecognizer:tapOtherPlayers];

将 "tapOtherPlayers" 变量设置为全局变量并将 UIGestureRecognizerDelegate 委托设置为如下所示。

@interface ViewController ()<UIGestureRecognizerDelegate>{
    UITapGestureRecognizer *tapOtherPlayers;
}

@end

@implementation ViewController
- (void)viewDidLoad {

    tapOtherPlayers = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapcollectionViewOtherPlayers:)];
    tapOtherPlayers.delegate = self;
    [tapOtherPlayers setNumberOfTapsRequired:1];
    [collectionViewOtherPlayers addGestureRecognizer:tapOtherPlayers];
}

希望这对您有所帮助...

您需要在 .h 文件中添加 UIGestureRecogniserDelegate,如下所示:

希望对您有所帮助..