Mac OS,控制台应用程序. performSelector:withObject:afterDelay:不起作用吗?

编程入门 行业动态 更新时间:2024-10-25 07:33:51
本文介绍了Mac OS,控制台应用程序. performSelector:withObject:afterDelay:不起作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在其中创建了一个简单的单例并运行方法:

I created a simple singleton and run method in it:

- (void)run { static int times = 0; NSLog(@"times = %d", times++); [self performSelector:@selector(run) withObject:nil afterDelay:MIN_DELAY]; }

但是它不能正常工作.它只能执行一次.

But it doesn't work properly. It is executed only once.

但是,如果我将performSelector:withObject:afterDelay:替换为performSelector:,那么它将被调用很多次(但我需要在两次调用之间延迟).

But if I replace performSelector:withObject:afterDelay: with performSelector: then it will be called a lot of times (but I need a delay between calls).

那么为什么方法performSelector:withObject:afterDelay:不起作用?我可以完全使用这种方法吗?

So why method performSelector:withObject:afterDelay: doesn't work? And can I use this method at all?

推荐答案

来自文档:

此方法向其当前上下文的运行循环进行注册,并依赖于定期运行的运行循环才能正确执行.

This method registers with the runloop of its current context, and depends on that runloop being run on a regular basis to perform correctly.

您没有运行循环.实际上,此方法无法为您正确执行.

You have no runloop. Ipso facto, this method does not perform correctly for you.

(创建和启动运行循环是调用UIApplicationMain的工作之一,但是当然您永远不会调用它.)

(Creating and starting a runloop is one of the things that calling UIApplicationMain does, but of course you are never calling it.)

更多推荐

Mac OS,控制台应用程序. performSelector:withObject:afterDelay:不起作用吗?

本文发布于:2023-11-15 22:09:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   不起作用   OS   Mac

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!