Xcode UITextView的指定初始值设定项
当我在Xcode 6 Beta中创建Xcode UITextView的指定初始值设定项,xcode,uitextview,swift,initializer,Xcode,Uitextview,Swift,Initializer,当我在Xcode 6 Beta中创建UITextView的新子类时,会自动提供以下代码 import UIKit class TerminalView: UITextView { init(frame: CGRect) { super.init(frame: frame) // Initialization code } } 前面的代码(完全由Xcode提供,没有删除任何内容)给出了以下错误 必须调用超类“UITextView”的指定初始值设
UITextView
的新子类时,会自动提供以下代码
import UIKit
class TerminalView: UITextView {
init(frame: CGRect) {
super.init(frame: frame)
// Initialization code
}
}
前面的代码(完全由Xcode提供,没有删除任何内容)给出了以下错误
必须调用超类“UITextView”的指定初始值设定项。
据我所知,为
UIView
的所有子类指定的。如果是这种情况,为什么Xcode提供的代码会导致错误?我没有向类中添加新的实例变量,因此还不需要初始化任何其他变量。似乎目前唯一有效的初始化器是:
super.init(frame: CGRect, textContainer: NSTextContainer?)
可以用
super.init(frame: CGRect.zero, textContainer: nil)
这很可能是初始测试版中的一个bug,将在即将发布的测试版中修复。2020年:
已提交错误。#17472321适用于任何想要检查状态的人。仍然未修复
class SpecialText: UITextView {
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
common()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
common()
}
private func common() {
backgroundColor = .yellow
font = .systemFont(ofSize: 26)
textColor = .green
}
}