按下时 UILabel 使应用程序崩溃
UILabel crashes app when pressed
您好,我是 iOS 应用程序编程的新手,遇到过这个问题。如果它是重复的,我很抱歉。我已经彻底搜索并(尝试)阅读了与此问题相关的所有线程,但 none 目前已修复它。
我正在尝试制作一个标签,当按下它时会变成其他东西。标签是在另一个 class 中创建的,并放在视图中。此外,我正在尝试在不放置按钮的情况下执行此操作。这是代码。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mountainImage: UIImageView!
@IBOutlet weak var mphView: Speed!
override func viewDidLoad() {
super.viewDidLoad()
setImage()
mphView.backgroundColor = UIColor(white: 0.2, alpha: 0.5)
mphView.layer.borderColor = UIColor(red: 222, green: 222, blue: 222, alpha: 1).CGColor
mphView.layer.borderWidth = 1
// Do any additional setup after loading the view, typically from a nib.
let touchSpeedLabel = UITapGestureRecognizer(target: self, action: "speedLabelTouched")
mphView.addGestureRecognizer(touchSpeedLabel)
mphView.userInteractionEnabled = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setImage(){
}
func speedLabelTouched(sender : UITapGestureRecognizer){
print("Lol this worked")
}
}
当我按下标签时,应用程序崩溃并出现此错误:
speedLabelTouched]:发送到实例 0x157d838c0 的无法识别的选择器
*** 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'unrecognized selector sent to instance 0x157d838c0'
在此先感谢您的帮助!
你告诉它使用一个名为 "speedLabelTouched" 的方法(无参数),但你已经实现了一个名为 "speedLabelTouched:" 的方法(一个参数)。
很合理,找不到无参数版本。
您好,我是 iOS 应用程序编程的新手,遇到过这个问题。如果它是重复的,我很抱歉。我已经彻底搜索并(尝试)阅读了与此问题相关的所有线程,但 none 目前已修复它。
我正在尝试制作一个标签,当按下它时会变成其他东西。标签是在另一个 class 中创建的,并放在视图中。此外,我正在尝试在不放置按钮的情况下执行此操作。这是代码。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mountainImage: UIImageView!
@IBOutlet weak var mphView: Speed!
override func viewDidLoad() {
super.viewDidLoad()
setImage()
mphView.backgroundColor = UIColor(white: 0.2, alpha: 0.5)
mphView.layer.borderColor = UIColor(red: 222, green: 222, blue: 222, alpha: 1).CGColor
mphView.layer.borderWidth = 1
// Do any additional setup after loading the view, typically from a nib.
let touchSpeedLabel = UITapGestureRecognizer(target: self, action: "speedLabelTouched")
mphView.addGestureRecognizer(touchSpeedLabel)
mphView.userInteractionEnabled = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setImage(){
}
func speedLabelTouched(sender : UITapGestureRecognizer){
print("Lol this worked")
}
}
当我按下标签时,应用程序崩溃并出现此错误:
speedLabelTouched]:发送到实例 0x157d838c0 的无法识别的选择器 *** 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'unrecognized selector sent to instance 0x157d838c0'
在此先感谢您的帮助!
你告诉它使用一个名为 "speedLabelTouched" 的方法(无参数),但你已经实现了一个名为 "speedLabelTouched:" 的方法(一个参数)。
很合理,找不到无参数版本。