[英]Cannot invoke 'UIView.init' with an argument list of type '(nibName: String?, bundle: Bundle?)'
My code for this is: 我的代码是:
import UIKit
class RCSubscriptionPackageView: UIView {
let centeredCollectionViewFlowLayout = CenteredCollectionViewFlowLayout()
let collectionView :UICollectionView
let cellPerWidth = 0.7
let container: UIView!
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
collectionView = UICollectionView(centeredCollectionViewFlowLayout: centeredCollectionViewFlowLayout)
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
Error is in the above initializer 上面的初始化程序中有错误
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .lightGray
collectionView.backgroundColor = .clear
centeredCollectionViewFlowLayout.itemSize = CGSize(
width: self.bounds.width * CGFloat(cellPerWidth),
height: self.bounds.height * CGFloat(cellPerWidth) * CGFloat(cellPerWidth)
)
centeredCollectionViewFlowLayout.minimumLineSpacing = 20
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = true
addContainerView()
addConstraintsForContainer()
collectionView.register(
RCSubscriptionPackCollectionViewCell.self,
forCellWithReuseIdentifier: String(describing: RCSubscriptionPackCollectionViewCell.self)
)
centeredCollectionViewFlowLayout.minimumLineSpacing = 20
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func addContainerView() -> Void {
container.backgroundColor = .lightGray
container.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(collectionView)
}
func addConstraintsForContainer() -> Void {
container.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
}
}
the error says 'Initializer does not override a designated initializer from its superclass' 错误显示“ Initializer不会从其超类覆盖指定的初始化程序”
and in 和在
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
error is 'Cannot invoke 'UIView.init' with an argument list of type '(nibName: String?, bundle: Bundle?)' 错误是“无法使用类型为'(nibName:String ?, bundle:Bundle?)'的参数列表调用'UIView.init'
I have searched about it every where but didn't got anything. 我到处都在搜索它,但是什么也没有。 Please get me out of this.
请让我摆脱这个。
UIView
supports these two initializers UIView
支持这两个初始化器
init(frame: CGRect)
init?(coder aDecoder: NSCoder)
init(nibName:bundle:
belongs to a view controller or a NIB init(nibName:bundle:
属于视图控制器或NIB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.