1
我有下面的代碼調試錯誤:調試初始化程序的問題?
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
這裏是我的所有代碼:
class ViewController: UIViewController {
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
var button = UIButton.buttonWithType(.Custom) as UIButton
button.frame = CGRectMake(160, 100, 50, 50)
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.setImage(UIImage(named:"thumbsUp.png"), forState: .Normal)
button.addTarget(self, action: "thumbsUpButtonPressed", forControlEvents: .TouchUpInside)
view.addSubview(button)
}
func thumbsUpButtonPressed() {
println("thumbs up button pressed")
}
錯誤說:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)
調試器輸出顯示如下:
fatal error: init(coder:) has not been implemented: file...hi/ViewController.swift, line 14
我以前有過這個錯誤,我不確定如何解決它。奇怪的是,有一個錯誤說You don't have any initializers
,並讓我把它放進去。它給我一個錯誤(有或沒有它)。
任何輸入和建議將不勝感激。
在此先感謝。
,爲什麼它有我輸入驗證碼,如果它使系統崩潰了? – Bigfoot11 2015-03-13 10:47:30
雖然謝謝。有效。我只想知道一些背景信息。 – Bigfoot11 2015-03-13 10:50:05
我想通過Xcode的方式告訴你你確實需要在這個類中實現這個編碼器,從而添加這個崩潰的行(通過觸發fatalError和一個關於缺少的編碼器的消息)。我同意這可能會令人困惑。 – Moritz 2015-03-13 10:53:30