how to use cancelPreviousPerformRequestsWithTarget

岁酱吖の 提交于 2019-12-12 06:12:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!