버튼을 만졌을 때만 나타나는 레이블을 만들고 싶습니다. 기능 숨겨진 때() 내가 ButtonAction 클래스 (동일한 기능) 내가 고전적인 오류 얻을에서 호출있을 때 그것은 잘 작동하지만 것 MainViewController에서 호출됩니다'선택 값을 언 래핑하는 동안 예기치 않게 nil이 발견되었습니다'
// MainViewController.swift
import UIKit
class MainViewController: UIViewController {
@IBOutlet weak var labelToShow: UILabel!
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
labelToShow.isHidden = true
}
func hidden() {
labelToShow.isHidden = true
}
func inHidden() {
labelToShow.isHidden = false
}
}
: 여기
Unexpectedly found nil while unwrapping an Optional value
를 코드입니다
AND :
// ButtonAction.swift
import UIKit
class ButtonAction: UIButton {
var touched:Bool = false
var mainScreen = MainViewController()
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
sleep(1)
mainScreen.hidden()
touched = true
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
mainScreen.inHidden()
touched = false
}
}
ButtonAction 클래스 및 ViewController를 만드는 방법에 대한 전체 코드를 표시 할 수 있습니까? –
[치명적인 오류 : 선택 값을 언 래핑하는 동안 예기치 않게 nil이 발견되었습니다 "는 의미는 무엇입니까?] (http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil- while-labelling-an-optional-valu) – rmaddy