将NSDictionary作为参数传递给UITapGestureRecognizer

编程入门 行业动态 更新时间:2024-10-05 11:16:05
本文介绍了将NSDictionary作为参数传递给UITapGestureRecognizer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I want to pass a NSArray as a parameter to UITapGestureRecognizer and access it in downloadOptionPressed method. How can I do this ?

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{ }

推荐答案

您是否有理由不能将信息存储在拥有的视图控制器中?是抽象吗?

Is there a reason you can't store the information in the owning view controller? Is it for abstraction?

您可以随时扩展UITapGestureRecognizer以携带更多数据:

You can always extend UITapGestureRecognizer to carry more data:

@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; }

更多推荐

将NSDictionary作为参数传递给UITapGestureRecognizer

本文发布于:2023-11-23 21:58:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   NSDictionary   UITapGestureRecognizer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!