开发者

Is there a setTimeout (like) in objective-c

开发者 https://www.devze.com 2023-01-24 16:59 出处:网络
Is there a similar setTimeout function in objective-c like in javascript?I dont want a sleep function.

Is there a similar setTimeout function in objective-c like in javascript? I dont want a sleep function.

I want to fire a "messa开发者_JAVA百科ge" after a period of time gone by but no locking up the device.


Try NSTimer.


As Calvin points you can use NSTimer class.

As an alternative you can use performSelector:withObject:afterDelay: method to schedule method call after specific delay (note that it is not guaranteed that delay will be exactly you specified - it just will be not less than that value)


See NSObject's performSelector:withObject:afterDelay:. You can also use NSTimer — it's particularly useful for mimicking setInterval(). And to execute arbitrary code instead of just sending a message, see Grand Central Dispatch's dispatch_after.

0

精彩评论

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