1

我正在尝试为我正在为 iOS8 使用的键盘创建自己的自定义视图类,当我创建一个扩展的新类时,我在加载键盘时UIView崩溃并出现错误。Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP,subcode=0x0)该错误显示在该行上class KeyButton: UIView {,我正在努力进一步调试。我最初试图扩展UIButton,但没有奏效,所以我将其更改为UIView没有进一步的运气。

我知道 Swift/iOS8 会有一些初期问题,但希望这是可以修复的!

编辑

完整类代码:

import UIKit

class KeyButton: UIView { /* This is where the app crashes, apparently */

    init(frame: CGRect) {
        super.init(frame: frame)
        // Initialization code
    }

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect)
    {
        // Drawing code
    }
    */

}
4

1 回答 1

3

我最近有一个类似的问题,但想通了。事实证明,在 iOS 8 中,而不是在 iOS 7 中,initWithCoder(在 Objective-C 中)是必需的。您所要做的就是将以下内容添加到您的课程中:

init(coder aDecoder: NSCoder!)
{
    super.init(coder: aDecoder)
}

我希望这会有所帮助!

于 2014-06-06T07:27:56.337 回答