gpt4 book ai didi

selector - 如何在 UIGestureRecognizer initWithTarget Action 中将参数传递给 Action

转载 作者:行者123 更新时间:2023-12-04 02:36:59 25 4
gpt4 key购买 nike

我正在使用下面的代码

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processTap)];

- (void) processTap
{
//do something
}

但我需要向 processTap 函数发送数据。有没有办法做到这一点?

最佳答案

示例:

UIImageView *myPhoto = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"tab-me-plese.png"]];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(processTap:)];

[myPhoto setTag:1]; //set tag value
[myPhoto addGestureRecognizer:tap];
[myPhoto setUserInteractionEnabled:YES];

- (void)processTap:(UIGestureRecognizer *)sender
{
NSLog(@"tabbed!!");
NSLog(@"%d", sender.view.tag);
}

关于selector - 如何在 UIGestureRecognizer initWithTarget Action 中将参数传递给 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11148415/

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