简体   繁体   English

无法使用类型为((nibName:String ?, bundle:Bundle?)'的参数列表调用'UIView.init'

[英]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.

相关问题 无法使用StringLiteralConvertible类型的参数列表调用&#39;init&#39; - Cannot invoke 'init' with argument list of type StringLiteralConvertible 无法使用类型&#39;的参数列表调用&#39;constraintsWithVisualFormat&#39;(字符串,选项:nil,metrics:nil,views:Dictionary <String, UIView!> )” - Cannot invoke 'constraintsWithVisualFormat' with an argument list of type '(String, options: nil, metrics: nil, views: Dictionary<String, UIView!>)' UIView.init()在哪里记录? - Where is UIView.init() documented? 无法使用类型为((String)&#39;的参数列表调用&#39;performSelector&#39; - Cannot invoke 'performSelector' with an argument list of type '(String)' 无法使用类型为&#39;(String)&#39;的参数列表调用&#39;enumerate&#39; - Cannot invoke 'enumerate' with an argument list of type '(String)' 无法使用类型为“(字符串)”的参数列表调用“追加” - Cannot invoke 'append' with an argument list of type '(String)' Swift:无法使用类型为'($ t3,NSString)'的参数列表调用'init' - Swift: Cannot invoke 'init' with an argument list of type '($t3, NSString)' 无法使用类型为参数的列表调用“ GameSetting.init” - Cannot invoke 'GameSetting.init' with an argument list of type UITableViewCell并且无法使用类型为((coder:NSCoder)&#39;的参数列表调用&#39;init&#39; - UITableViewCell and Cannot invoke 'init' with an argument list of type '(coder: NSCoder)' 无法调用类型为((String)&#39;的参数列表的&#39;implode&#39; - Cannot invoke 'implode' with an argument list of type '(String)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM