gpt4 book ai didi

objective-c - [UITapGestureRecognizer 标签] : unrecognized selector sent to instance

转载 作者:太空狗 更新时间:2023-10-30 03:22:30 26 4
gpt4 key购买 nike

我正在安排一系列 imageview,并为其分配一个 TapView 识别器

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(action:)];
[tapRecognizer setNumberOfTouchesRequired:1];
[tapRecognizer setDelegate:self];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tapRecognizer];

并且我将选择器定义为:

-(void) action:(id)sender
{
NSLog(@"TESTING TAP");
NSLog (@"%d",[sender tag]);
}

这正在崩溃,我收到的错误消息是:-

[UITapGestureRecognizer 标签]:无法识别的选择器发送到实例 0x145d0210

最佳答案

你可以用这个..

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(action:)];
[tapRecognizer setNumberOfTouchesRequired:1];
[tapRecognizer setDelegate:self];
imageView.userInteractionEnabled = YES;
imageView.tag = 1111;
[imageView addGestureRecognizer:tapRecognizer];

并在行动中尝试这个..

-(void) action:(id)sender
{
NSLog(@"TESTING TAP");
UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
NSLog (@"%d",[tapRecognizer.view tag]);
}

解释:

UITapGestureRecognizer 没有像 tag 这样的属性。但是它有属性 view,从这个属性你可以访问附加了 UITapGestureRecognizer 的 View 。

希望对你有帮助

关于objective-c - [UITapGestureRecognizer 标签] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19152573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com