2017-10-16 1 views
0

für diese Mein Code ist:Kann 'UIView.init' mit einer Argumentliste vom Typ aufrufen '(nibName: String ?, Bundle: Bundle?)'

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) 
} 

Fehler in der oben initializer ist

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() 
    } 
} 


} 

der Fehler sagt

und in

'initializer keine bestimmte Initialisierung von seiner übergeordneten Klasse nicht außer Kraft setzen'

Fehler ist UIView.init ‚mit einem Argument Liste vom Typ‚‚nicht aufrufen‘ (nibName: String ?, Bundle: Bundle?)‘

ich darüber gesucht allenthalben, aber nicht bekam etwas. Bitte hol mich hier raus.

Antwort

0

UIView unterstützt diese beiden Initialisierungen

  • init(frame: CGRect)
  • init?(coder aDecoder: NSCoder)

init(nibName:bundle: zu einer Ansicht gehört Controller oder eine NIB

Verwandte Themen