Ошибка UICollectionViewDelegateFlowLayout даже после предоставления макета - PullRequest
0 голосов
/ 01 октября 2019

Видя следующее исключение

'UICollectionView must be initialized with a non-nil layout parameter'

с этим ViewController

import UIKit

class SelectDesignController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
    private let designCellId = "designCellId"

    override func viewDidLoad() {
        super.viewDidLoad()
        configureNavBar()
        configureUI()
        collectionView.backgroundColor = #colorLiteral(red: 0.8515156507, green: 0.9521961808, blue: 0.9503603578, alpha: 1)
        collectionView.register(DesignCategoryCell.self, forCellWithReuseIdentifier: designCellId)
    }
    @objc func handleDismiss() {
        dismiss(animated: true, completion: nil)
    }

    func configureNavBar() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage.fontAwesomeIcon(name: .chevronLeft, style: .solid, textColor: .white, size: CGSize(width: 40, height: 40)).withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleDismiss))
    }
    func configureUI (){
        view.backgroundColor = #colorLiteral(red: 0.8515156507, green: 0.9521961808, blue: 0.9503603578, alpha: 1)
    }
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: designCellId, for: indexPath) as! DesignCategoryCell
        return cell
    }
    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }
    /** PROVIDING a LAYOUT HERE **/
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: view.frame.width, height: view.frame.height)
    }

}

Я включаю SelectDesignController следующим образом:

let controller = SelectDesignController()
let nav = UINavigationController(rootViewController: controller)
configureNav(nav: nav, title: "Designs")
present(nav, animated: true, completion: nil)

Любая идея,что мне не хватает?

1 Ответ

0 голосов
/ 01 октября 2019

Вы должны проверить 2 вещи:

frame

Прямоугольник рамки для вида коллекции, измеренный в точках. Источник кадра относится к суперпредставлению, в которое вы планируете добавить его. Этот кадр передается суперклассу во время инициализации.

layout

Объект макета, используемый для организации элементов. Представление коллекции хранит строгую ссылку на указанный объект. Не должно быть ноль.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...