问题
I have a method in scrollView:didScroll like this:
[self.navigationCollectionView moveWhiteLineToPointX:middleX WithWidth:middleWidth animated:NO];
I don't want this method be called multiple times if user is scrolling fast, so I want to use +cancelPreviousPerformRequestsWithTarget:selector:object
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument
I don't know how to feed the correct parameters for this API, especially for the target and the argument. Could someone help?
回答1:
try this
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(scrollViewDidScroll:) object:nil];
回答2:
For canceling:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(yourSelectorFunction) object:nil];
And for calling perform selector:
[self performSelector:@selector(yourSelectorFunction) withObject:nil afterDelay:0.4];
来源:https://stackoverflow.com/questions/30100259/how-to-use-cancelpreviousperformrequestswithtarget