djud17-org / SB-MDEditor

1 stars 1 forks source link

M3L1 Доработать OpenDoc module #37

Closed SShliakhin closed 1 year ago

SShliakhin commented 1 year ago

Еще дам инфу как правильно регистрировать ячейки по модели

Новый функционал

SShliakhin commented 1 year ago

Регистрация ячейк по модели, сделать аналогично как для CollectionView, пример кода есть в базе:

// регистрация

collectionView.register(models: [
            RecentFileCell.RecentFileCellModel.self,
            MenuItemCell.MenuItemCellModel.self
        ])

// создание

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let sections = sectionManager.getSections()

        let model: CellViewAnyModel
        switch sections[indexPath.section] {
        case .recentFiles:
            // заменить данные
            model = RecentFileCell.RecentFileCellModel(fileCoverColor: .brown, fileName: "Test")
        case .menu:
            // заменить данные
            model = MenuItemCell.MenuItemCellModel(itemIcon: .init(systemName: "menucard"), itemName: "Открыть")
        }

        return collectionView.dequeueReusableCell(withModel: model, for: indexPath)
    }

// в самом классе ячейки

// MARK: - CellViewModel extension

extension RecentFileCell.RecentFileCellModel: CellViewModel {
    func setup(cell: RecentFileCell) {
        cell.fileCoverView.backgroundColor = fileCoverColor
        cell.fileNameLabel.text = fileName
    }
}
SShliakhin commented 1 year ago

закрыто через https://github.com/djud17-org/SB-MDEditor/issues/47