HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了IOS:在@selector中添加一个参数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这行代码
UILongPressGestureRecognizer *downWARDGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@SELEctor(dragGestureChanged:)];@H_419_3@ 
 

还有这个

- (void)dragGestureChanged:(UILongPressGestureRecognizer*)gesture{
...
}@H_419_3@ 
 

我想在“@SELEctor(dragGestureChanged :)”中添加一个参数即“(UIScrollView *)scrollView”,我该怎么办

解决方法

你不能直接–UIGestureRecognizers知道如何发出一个只接受一个参数的选择器的调用.要完全一般,你可能希望能够传递一个块.苹果公司还没有这样做,但它很容易添加,至​​少如果你愿意将手势识别器子类化,你想要解决添加属性和正确清理的问题,而不深入研究运行时.

所以,例如(我去的时候写的,未经检查)

typedef void (^ recogniserBlock)(UIGestureRecognizer *recogniser);

@interface UILongPressGestureRecognizerWithBlock : UILongPressGestureRecognizer

@property (nonatomic,copy) recogniserBlock block;
- (id)initWithBlock:(recogniserBlock)block;

@end

@implementation UILongPressGestureRecognizerWithBlock
@synthesize block;

- (id)initWithBlock:(recogniserBlock)aBlock
{
    self = [super initWithTarget:self action:@SELEctor(dispatchBlock:)];

    if(self)
    {
         self.block = aBlock;
    }

    return self;
}

- (void)dispatchBlock:(UIGestureRecognizer *)recogniser
{
    block(recogniser);
}

- (void)dealloc
{
    self.block = nil;
    [super dealloc];
}

@end@H_419_3@ 
 

然后你就可以这样做:

UILongPressGestureRecognizer = [[UILongPressGestureRecognizerWithBlock alloc] 
        initWithBlock:^(UIGestureRecognizer *recogniser)
        {
            [someObject relevantSELEctorWithRecogniser:recogniser 
                      scrollView:relevantScrollView];
        }];@H_419_3@

大佬总结

以上是大佬教程为你收集整理的IOS:在@selector中添加一个参数全部内容,希望文章能够帮你解决IOS:在@selector中添加一个参数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。