参数 – 如何使用Swift NSTimer调用其选择器来修复错误
发布时间:2020-12-14 04:41:51 所属栏目:百科 来源:网络整理
导读:我收到运行时错误: 2014-07-15 16:49:44.893 TransporterGUI [1527:303] – [_ TtC14TransporterGUI11AppDelegate printCountdown]:无法识别的选择器发送到实例0x10040e8a0 当我使用以下Swift代码来触发计时器时: @IBAction func schedule(sender : An
我收到运行时错误:
2014-07-15 16:49:44.893 TransporterGUI [1527:303] – [_ TtC14TransporterGUI11AppDelegate printCountdown]:无法识别的选择器发送到实例0x10040e8a0 当我使用以下Swift代码来触发计时器时: @IBAction func schedule(sender : AnyObject) { var startTime = startDatePicker.dateValue.timeIntervalSinceDate(NSDate()) var endTime = endDatePicker.dateValue.timeIntervalSinceDate(startDatePicker.dateValue) var startDate = NSDate.date() let params = ["startTime": startTime,"startDate": startDate] var counter = NSTimer.scheduledTimerWithTimeInterval(1.0,target:self,selector:Selector("printCountdown"),userInfo:params,repeats:true) } func printCountdown(timer: NSTimer) { var userInfo = timer.userInfo as NSDictionary var startTime = userInfo["startTime"] as NSTimeInterval var startDate = userInfo["startDate"] as NSDate var elapsedTime: NSTimeInterval = NSDate.date().timeIntervalSinceDate(startDate) var remainingTime: NSTimeInterval = startTime - elapsedTime; if (remainingTime <= 0.0) { timer.invalidate() transferLabel.title = "No transfer scheduled" } transferLabel.title = remainingTime.description } 奇怪的是,如果我将函数printCountdown的签名更改为没有参数,则会正确调用该函数,但是我无法访问进行调用的计时器对象. 提前致谢! 解决方法
您的选择器应为“printCountdown:”,带有终止冒号以指示选择器采用参数.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- Flex中的CSS: (3)CSS会被编译器转换为什么样的
- c – 为什么我的无锁消息队列是segfault :(?
- Oracle建表、更新、查询综合练习
- ruby-on-rails – ActiveRecord在脏(未保存)关系
- ruby-on-rails-3 – Rails rspec和omniauth(集成
- c# – 如何在构造函数中设置属性值(显式接口实现
- ajax – 在GET上期待JSON结果时,Angularjs $http
- ruby-on-rails – 在验收测试中加快Paperclip的图
- c# – .NET – 将语句lambda body转换为字符串
- C语言模拟实现C++的继承与多态示例
热点阅读