我收到运行时错误:
2014-07-15 16:49:44.893 TransporterGUI [1527:303] – [_ TtC14TransporterGUI11AppDelegate printCountdown]:无法识别的选择器发送到实例0x10040e8a0
@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:”,带有终止冒号以指示选择器采用参数.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。