How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?(您如何在延迟后触发块,例如 -performSelector:withObject:afterDelay:?)
问题描述
有没有办法在延迟后调用带有原始参数的块,例如使用 performSelector:withObject:afterDelay:
但带有像 int
/double
/float
?
Is there a way to call a block with a primitive parameter after a delay, like using performSelector:withObject:afterDelay:
but with an argument like int
/double
/float
?
推荐答案
我想你正在寻找 dispatch_after()
.它要求您的块不接受任何参数,但您可以让块从本地范围捕获这些变量.
I think you're looking for dispatch_after()
. It requires your block to accept no parameters, but you can just let the block capture those variables from your local scope instead.
int parameter1 = 12;
float parameter2 = 144.1;
// Delay execution of my block for 10 seconds.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSLog(@"parameter1: %d parameter2: %f", parameter1, parameter2);
});
更多:https://developer.apple.com/documentation/dispatch/1452876-dispatch_after
这篇关于您如何在延迟后触发块,例如 -performSelector:withObject:afterDelay:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您如何在延迟后触发块,例如 -performSelector:withObject:afterDelay:?
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01