ios - 无法识别的选择器发送到实例 0x7f995be07650
问题描述
我有最新更新的 Xcode。我刚开始快速学习,但我遇到了错误。请帮忙。谢谢
2018-07-31 06:30:29.085754+1200 swift4[2874:61277]-[swift4.ViewController uda1]:无法识别的选择器发送到实例 0x7fe13f6122a0 2018-07-31 06:30:29.089728+1200 swift4[2874:61277] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[swift4.ViewController uda1]:无法识别的选择器发送到实例 0x7fe13f6122a0” *** 首先抛出调用堆栈: ( 0 核心基础 0x0000000102dfd1e6 __exceptionPreprocess + 294 1 libobjc.A.dylib 0x0000000102492031 objc_exception_throw + 48 2核心基础0x0000000102e7e784-[NSObject(NSObject)不识别选择器:]+132 3 UIKit 0x00000001034a86db-[UIResponder doesNotRecognizeSelector:] + 295 4核心基础0x0000000102d7f898 ___转发___ + 1432 5 核心基础 0x0000000102d7f278 _CF_forwarding_prep_0 + 120 6 基础 0x0000000101efc4dd __NSFireTimer + 83 7 核心基础 0x0000000102d8ce64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 8 核心基础 0x0000000102d8ca52 __CFRunLoopDoTimer + 1026 9 核心基础 0x0000000102d8c60a __CFRunLoopDoTimers + 266 10 核心基础 0x0000000102d83e4c __CFRunLoopRun + 2252 11 核心基础 0x0000000102d8330b CFRunLoopRunSpecific + 635 12 图形服务 0x00000001089d1a73 GSEventRunModal + 62 13 UIKit 0x000000010327a057 UIApplicationMain + 159 14 swift4 0x0000000101b86927 主要 + 55 15 libdyld.dylib 0x000000010720d955 开始 + 1 ) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)
我收到错误:
在我的视图控制器中:
import UIKit
class ViewController: UIViewController {
var timer1 = Timer()
var counter = 0
@IBOutlet weak var Label: UILabel!
@IBAction func Start(_ sender: Any) {
counter = 0
Label.text = String (counter)
timer1 = Timer.scheduledTimer(timeInterval: 1, target: self, selector: ("uda1") , userInfo: nil, repeats: true);
}
func uda1 ()
{
counter += 1
Label.text = String(counter)
}
@IBAction func Stop(_ sender: Any) {
timer1.invalidate()
}
}
解决方案
你可以试试
timer1 = Timer.scheduledTimer(timeInterval: 1, target: self, #selector(uda1) , userInfo: nil, repeats: true);
//
@objc func uda1()
{
counter += 1
Label.text = String(counter)
}
//
var timer1:Timer?
//
timer1?.invalidate()
推荐阅读
- wcf - 无法在 ASP.NET Core 5.0 下的 IIS 中托管 CoreWcf
- angular - 我想将日期转换为 dd-mm-yyyy
- python - 尝试从 gstreamer appsink 获取 numpy 图像导致缓冲区太小错误
- node.js - 是否有一种直接的方式来验证 Joi 中的多个条件
- python - SIFT 无法关联清晰相关的图像
- timer - 我想使用两个不同的时间通过单个 UART 发送和接收数据
- python - 如何使用 python 将特定的 xml 标签移动到新的 xml 文件?
- java - 使用 telnet 连接通过 java 代码向 Digi 发送 Ctrl+Break
- windows - 不能有一个零长度的 USB“串行”字符串描述符?
- reactjs - mui DataGrid 滚动条在 columnHeader 上不起作用