为UIGestureRecognizer设置委托以发出警告

时间:2016-05-05 03:03:24

标签: ios objective-c uitapgesturerecognizer

为UITapGesture设置委托给出警告

Assigning to 'id<UIGestureRecognizerDelegate>_Nullable' from incompatible type 'TopPlayersViewController *const+strong'

这是我的代码:

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

2 个答案:

答案 0 :(得分:3)

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

enter image description here

希望有所帮助......

答案 1 :(得分:1)

制作&#34; tapOtherPlayers&#34;变量为全局变量,并将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];
}

希望这会对你有帮助......