
import UIKitclass CardVIEw: UIVIEw { @IBOutlet var imageVIEw: UIImageVIEw! init(imageVIEw: UIImageVIEw) { self.imageVIEw = imageVIEw super.init(frame: CGRect(x: 0,y:0,wIDth: self.frame.size.wIDth,height: self.frame.size.height)) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }} 我在行上收到错误:
super.init(frame: CGRect(x: 0,height: self.frame.size.height))
错误说明在super.init初始化self之前在属性访问’frame’中使用’self’
我不知道如何解决这个问题.
请记住,我来自客观 – C背景,最近开始学习迅捷.
解决方法 在init()方法中访问self之前,必须调用super.init():init(imageVIEw: UIImageVIEw) { self.imageVIEw = imageVIEw /*you are accessing self here before calling super init*/ super.init(frame: CGRect(x: 0,wIDth: self.frame.size.wIDth /* here also*/,height: self.frame.size.height))} 将其更改为:
init(imageVIEw: UIImageVIEw) { super.init(frame: CGRect(origin: CGPoint.zero,size: imageVIEw.frame.size)) self.imageVIEw = imageVIEw } 总结 以上是内存溢出为你收集整理的ios – 在super.init初始化self之前,在属性访问’frame’中使用’self’全部内容,希望文章能够帮你解决ios – 在super.init初始化self之前,在属性访问’frame’中使用’self’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)