Ich versuche, meine UICollectionView in meiner benutzerdefinierten UIView zu haben, kann zu einer Seite blättern, wenn eine Taste in der Haupt-VC gedrückt wird. Leider stürzt ich jedes Mal, wenn ich die Methode im MainVC anrufe, ab, @, um scrollToItem.UICollectionView ScrollTo Abstürzen
Hier ist mein MainVC.
let mainView = MainViewsHome()
Im ViewWillAppear:
/** Setting up the bottom half **/
mainView.frame = CGRect(x:self.view.frame.width * 0, y:self.view.frame.height/6.2, width:self.view.frame.width,height:self.view.frame.height/1.1925)
mainView.backgroundColor = UIColor.clear
self.view.addSubview(mainView)
& & Meine benutzerdefinierte UIView
class MainViewsHome: UIView, UIGestureRecognizerDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
var cellId = "Cell"
var collectionView : UICollectionView!
override init(frame: CGRect) {
super.init(frame: CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/1.3))
/**Creation of the View **/
let flowLayout : UICollectionViewFlowLayout = UICollectionViewFlowLayout()
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
flowLayout.scrollDirection = .horizontal
let collectionView = UICollectionView(frame: CGRect(x:self.frame.width * 0,y:self.frame.height * 0,width:self.frame.width,height: self.frame.height), collectionViewLayout: flowLayout)
collectionView.register(uploadGenreSelectionCVC.self, forCellWithReuseIdentifier: cellId)
collectionView.isPagingEnabled = true
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = UIColor.purple
self.addSubview(collectionView)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func moveToPage() {
print("we are moving to page")
self.collectionView.scrollToItem(at: 2 as IndexPath, at: UICollectionViewScrollPosition.right, animated: true)
}
& & Da ist in meinem MainVC Ich rufe: mainView.moveToPage()
Wo ich mit meinem Verständnis falsch werde?
können Sie bitte den Absturz posten? – Siriss