不能援引“UIView.init”类型的参数列表“(nibName:字符串?包:包吗?)”
问题描述:
我对这个代码是:不能援引“UIView.init”类型的参数列表“(nibName:字符串?包:包吗?)”
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)
}
错误是在上面的初始化
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()
}
}
}
错误说
和
“初始化程序不自其超重写指定初始化”错误是 “不能援引‘UIView.init’类型的参数列表‘(nibName:字符串?包:包吗?)’
...我已经寻找它的每一个地方,但没有得到任何东西。 请把我弄出来。
答
UIView
支持这两种初始化
init(frame: CGRect)
init?(coder aDecoder: NSCoder)
init(nibName:bundle:
属于视图控制器或NIB