簡體   English   中英

按下時,UILabel使應用程序崩潰

[英]UILabel crashes app when pressed

嗨,我是iOS應用程序編程的新手,遇到了這個問題。 對不起,如果重復的話。 我已經進行了徹底的搜索,並(試圖)閱讀了與此問題相關的所有主題,但到目前為止,都沒有一個解決的方法。

我正在嘗試制作一個標簽,該標簽在按下時會更改為其他內容。 標簽是在另一個類中創建的,並放置在視圖中。 我也試圖做到這一點,而無需在其后面放置按鈕。 這是代碼。

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'而終止了應用程序,原因:'無法識別的選擇器已發送到實例0x157d838c0'

在此先感謝您的幫助!

您要告訴它使用一種名為“ speedLabelTouched”的方法(無參數),但是您已經實現了一種名為“ speedLabelTouched:”的方法(一個參數)。

相當合理地,它找不到無參數版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM