首页 > 解决方案 > 如何在使用 UITableViewDiffableDataSource 时设置表格视图单元格的高度(如 heightForRowAt)

问题描述

我想在使用 DiffableDataSource 时检查如何设置 tableview 单元格的高度。这是代码:

func configureDataSource() {
    dataSource = MenuItemDataSource(tableView: MenuItemTablevVew, cellProvider: { (tableView, indexPath, menuItem) -> UITableViewCell? in
        
        guard let cell = tableView.dequeueReusableCell(withIdentifier: self.cellIdentifier) as? MenuItemTableCell else {  fatalError("Cell not exists")
        }
        
        cell.data = menuItem
        return cell
    })
    
}

func createSnapshot(menuItems: [MenuItemModel]) {
    var snapshot = MenuItemSnapshot()
    snapshot.appendSections([.First])
    snapshot.appendItems(menuItems)
    dataSource.apply(snapshot, animatingDifferences: false)
}

标签: iosswifttableview

解决方案


推荐阅读