本文介绍了使用 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

  1. pSwOaD 只接受一个参数
  2. setEditing:animated: 的第二个参数是原始 BOOL - 不是对象
  1. pSwOaD only accepts one parameter
  2. 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: 带非对象参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 14:18