NSTimer具有匿名功能/块? [英] NSTimer with anonymous function / block?

查看:48
本文介绍了NSTimer具有匿名功能/块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将来可以安排三个小事件而无需为每个事件编写一个函数。如何使用 NSTimer 执行此操作?我理解块有助于匿名功能,但它们可以在 NSTimer 中使用,如果是,如何使用?

I want to be able to schedule three small events in the future without having to write a function for each. How can I do this using NSTimer? I understand blocks facilitate anonymous functions but can they be used within NSTimer and if so, how?

[NSTimer scheduledTimerWithTimeInterval:gameInterval  
         target:self selector:@selector(/* I simply want to update a label here */) 
         userInfo:nil repeats:NO];


推荐答案

您实际上可以致电:

NSTimer.scheduledTimerWithTimeInterval(ti: NSTimeInterval,
                    target: AnyObject, 
                    selector: #Selector, 
                    userInfo: AnyObject?, 
                    repeats: Bool)

像这样使用:

NSTimer.scheduledTimerWithTimeInterval(1, 
                    target: NSBlockOperation(block: {...}), 
                    selector: #selector(NSOperation.main), 
                    userInfo: nil, 
                    repeats: true)

这篇关于NSTimer具有匿名功能/块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆