Pass a NSDictionary as parameter to UITapGestureRecognizer

后端 未结 3 1588
悲&欢浪女
悲&欢浪女 2020-12-11 08:31

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

The

3条回答
  •  感情败类
    2020-12-11 09:05

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

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

提交回复
热议问题