Dea*_*Lee 6 initialization uikit ios swift
我有一个派生自UIView的类,但我初始化它总是显示错误说"属性'self.title'未在swift中的super.init调用中初始化"
这是我的代码
class A: UIView
{
var title : String
var recordUrl : String
var content : String
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
init(frame : CGRect ,title : String, recordUrl : String , content : String)
{
super.init(frame: frame)
self.title = title
self.recordUrl = recordUrl
self.content = content
}
}
Run Code Online (Sandbox Code Playgroud)
小智 8
init(frame : CGRect ,title : String, recordUrl : String , content : String) {
self.title = title
self.recordUrl = recordUrl
self.content = content
super.init(frame: frame)
}
Run Code Online (Sandbox Code Playgroud)
在swift中,你应该首先初始化你的参数,然后实现super.Method()
| 归档时间: |
|
| 查看次数: |
7706 次 |
| 最近记录: |