Hi I am very new to programing for iOS apps and have come across this issue. I am sorry if it is a duplicate. I have searched thoroughly and have (tried) to read all relating threads to this issue but none have fixed it so far.
I am attempting to make a label that when pressed changes to something else. The label is created in another class and is put inside a view. Also I am trying to do this without putting a button behind it. Here is that code.
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")
}
}
When I press the Label the app crashes with this error:
speedLabelTouched]: unrecognized selector sent to instance 0x157d838c0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unrecognized selector sent to instance 0x157d838c0'
Thanks in advance for helping!
You're telling it to use a method called "speedLabelTouched" (no parameters) but you've implemented a method called "speedLabelTouched:" (one parameter).
It, quite reasonably, can't find the no parameter version.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.