本文介绍了使用performSelector:withObject:afterDelay:带有非对象参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在表视图上稍微延迟地调用 setEditing:animated:
。通常,我会使用 performSelector:withObject:afterDelay:
,但
I want to invoke setEditing:animated:
on a table view with a slight delay. Normally, I'd use performSelector:withObject:afterDelay:
but
- pSwOaD only接受一个参数
- 第二个参数
setEditing:animated:
是原始BOOL - 不是对象
- pSwOaD only accepts one parameter
- the second parameter to
setEditing:animated:
is a primitive BOOL - not an object
在过去,我将在自己的类中创建一个虚方法,如 setTableAnimated
,然后调用 [self performSelector:@selector(setTableAnimated)withObject:nil afterDelay:0.1f
但是对我感觉很丑。
In the past I would create a dummy method in my own class, like setTableAnimated
and then call [self performSelector:@selector(setTableAnimated) withObject:nil afterDelay:0.1f
but that feels kludgy to me.
有更好的方法吗?
推荐答案
为什么不使用dispatch_queue?
Why not use a dispatch_queue ?
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[tableView setEditing …];
});
这篇关于使用performSelector:withObject:afterDelay:带有非对象参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!