开发者

Cocoa - Pause a method

开发者 https://www.devze.com 2023-02-03 02:57 出处:网络
How would I go ahead about pausing a method without freezing the UI, and then continuing the process when told?

How would I go ahead about pausing a method without freezing the UI, and then continuing the process when told?

Thanks,

开发者_如何学GoKevin


There's not a way to interrupt execution of an arbitrary method and to then resume it later.

You can break your method into multiple pieces that represent the units of work that you want to be able to pause between. You can then use timers (either NSTimers or [NSObject performSelector:withObject:afterDelay:] for a specific pause interval.

More information on what you're trying to do might allow for some more specifically useful suggestions here.


There is a method to prevent the UI from stopping and eg. timers too. This is more or less the whole reason why we have run loops (well, thats not really true but in your case it is).

Just insert this into your function and everything will work:

while(pauseFunction)
{
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1f]];
}

Remark: Everything scheduled with the runloop keeps running, this is the UI, timers, networking etc. pp.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号