Вопросы

SWIFT: Как программно установить размер кадра представления коллекции, чтобы он был равен его родительскому виду?

Я реализую collectionView программно:

class collectionViews {
     static func collectionViewOne() -> UICollectionView {
        let flowLayout = CarouselFlowLayout()
        let collectionViewOne = UICollectionView(frame: CGRect(x: 106, y: 313, width: 1708, height: 300), collectionViewLayout: flowLayout)
        return collectionViewOne
    }
}

Я показываю его внутри TableViewCell TableView, который также реализован программно:

class TableViewCell2: UITableViewCell {
    var moviesItems: [movieItem] = []
    let cellIdentifier = "movieCardCell"
    let collectionViewOne = collectionViews.collectionViewOne()

    private func setupCollectionView(){

        collectionViewOne.delegate = self
        collectionViewOne.dataSource = self
        collectionViewOne.backgroundColor = UIColor (hex: "444A64")
         collectionViewOne.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "MyCell")
                 let nib = UINib(nibName: "movieCardCell", bundle: nil)
        collectionViewOne.register(nib, forCellWithReuseIdentifier: cellIdentifier)
 self.contentView.addSubview(collectionViewOne)

    }
}

// These functions never get called
 extension TableViewCell:  UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
     print("INSIDE TableViewCell2.collectionView 1")
     return 1
 }
 
 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath)
     print("INSIDE TableViewCell2.collectionView 2")
     return cell
 }
 
 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
     // For some reason he chose the measures of collectionViewCell and substracted 2
     print("INSIDE TableViewCell2.collectionView 3")
     return CGSize(width: 139, height: 64)
 }
 }

Я хочу, чтобы размер фрейма collectionView был равен размеру фрейма TableViewCell: Итак, есть идеи, что я должен здесь изменить, если это возможно?

 let collectionViewOne = UICollectionView(frame: CGRect(x: 106, y: 313, width: 1708, height: 300), collectionViewLayout: flowLayout)
Читать:
VSCode: сохраняйте фокус в Viewlet управления версиями при открытии файла

Похожие записи

Примечание: неопределенный индекс: родительский при добавлении множественного выбора в админке Sonata

admin

Различные уровни доступа для AWS Cognito

admin

Не удается получить динамическое представление прокрутки, размер которого соответствует его содержимому, работающему

admin

Как вы вызываете несколько файлов из командной строки в свое приложение?

admin

Отсутствующие метрики для конвейера Apache Beam (через SparkRunner / Dataproc)

admin

Интегрируйте Stripe 3d secure в IOS

admin