【发布时间】:2015-07-04 06:08:16
【问题描述】:
我正在尝试创建 UIBezierPath 的子类来添加一些对我有用的属性。
class MyUIBezierPath : UIBezierPath {
var selectedForLazo : Bool! = false
override init(){
super.init()
}
/* Compile Error: Must call a designated initializer of the superclass 'UIBezierPath' */
init(rect: CGRect){
super.init(rect: rect)
}
/* Compile Error: Must call a designated initializer of the superclass 'UIBezierPath' */
init(roundedRect: CGRect, cornerRadius: CGFloat) {
super.init(roundedRect: roundedRect, cornerRadius: cornerRadius)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
编辑: 我需要这个,因为在我的代码中我写了
var path = MyUIBezierPath(roundedRect: rect, cornerRadius: 7)
它会导致编译错误:
"必须调用超类 'UIBezierPath' 的指定初始化程序"
我尝试在子类中添加该初始化程序,但似乎不起作用。
你能帮帮我吗?
【问题讨论】:
-
“这不起作用”是什么意思?去掉 intWithCoder 中的 fatalError 行,将其替换为对 super 的调用。
-
我想你只需要实现initWithCoder:。在那个中添加对 super 的调用,然后删除其他的。
-
好的,我再问一次。 “不起作用”是什么意思?这对试图帮助你的人来说是完全没用的。你需要说出发生了什么。它不编译吗?跑的时候会不会死机?什么?具体一点。
标签: ios swift inheritance subclass uibezierpath