将NSDictionary作为参数传递给UITapGestureRecognizer [英] Pass a NSDictionary as parameter to UITapGestureRecognizer

查看:91
本文介绍了将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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆