gpt4 book ai didi

ios - 将 NSDictionary 作为参数传递给 UITapGestureRecognizer

转载 作者:可可西里 更新时间:2023-11-01 05:02:00 24 4
gpt4 key购买 nike

我想将 NSArray 作为参数传递给 UITapGestureRecognizer 并在 downloadOptionPressed 方法中访问它。我该怎么做?

NSArray

NSArray *parameters = [NSArray arrayWithObjects:currentTrack, nil];

创建UITapGestureRecognizer

UITapGestureRecognizer *downloadOptionPressed = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(timeFrameLabelTapped:)];
[downloadOption addGestureRecognizer:downloadOptionPressed];

downloadOptionPressed 方法

-(void)downloadOptionPressed:(UIGestureRecognizer*)recognizer{

}

最佳答案

您不能将信息存储在拥有的 View Controller 中有什么原因吗?是为了抽象吗?

您始终可以扩展 UITapGestureRecognizer 以携带更多数据:

@interface UserDataTapGestureRecognizer : UITapGestureRecognizer
@property (nonatomic, strong) id userData;
@end

@implementation UserDataTapGestureRecognizer
@end

...

UserDataTapGestureRecognizer *downloadOptionPressed =
[[UserDataTapGestureRecognizer alloc] initWithTarget:self
action:@selector(timeFrameLabelTapped:)];
downloadOptionPressed.userData = parameters;

...

- (void)downloadOptionPressed:(UserDataTapGestureRecognizer *)recognizer {
NSArray *parameters = recognizer.userData;
}

关于ios - 将 NSDictionary 作为参数传递给 UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16110422/

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