简体   繁体   English

按下时,UILabel使应用程序崩溃

[英]UILabel crashes app when pressed

Hi I am very new to programing for iOS apps and have come across this issue. 嗨,我是iOS应用程序编程的新手,遇到了这个问题。 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' speedLabelTouched]:无法识别的选择器已发送到实例0x157d838c0 ***由于未捕获的异常'NSInvalidArgumentException'而终止了应用程序,原因:'无法识别的选择器已发送到实例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). 您要告诉它使用一种名为“ speedLabelTouched”的方法(无参数),但是您已经实现了一种名为“ speedLabelTouched:”的方法(一个参数)。

It, quite reasonably, can't find the no parameter version. 相当合理地,它找不到无参数版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM