UILongPressGestureRecognizer *downwardGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChanged:)];
还有这个
- (voID)dragGestureChanged:(UILongPressGestureRecognizer*)gesture{...}
我想在“@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
然后你就可以这样做:
UILongPressGestureRecognizer = [[UILongPressGestureRecognizerWithBlock alloc] initWithBlock:^(UIGestureRecognizer *recogniser) { [someObject relevantSelectorWithRecogniser:recogniser scrollVIEw:relevantScrollVIEw]; }];总结
以上是内存溢出为你收集整理的IOS:在@selector中添加一个参数全部内容,希望文章能够帮你解决IOS:在@selector中添加一个参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)