forkingdog / UITableView-FDTemplateLayoutCell

Template auto layout cell for automatically UITableViewCell height calculating
MIT License
9.94k stars 2.01k forks source link

Archive #408

Open grand-china opened 4 years ago

grand-china commented 4 years ago

cache the height to model, may is anythings you want

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdForMessage(msg:array[safe: indexPath.row]), for: indexPath)

        if let model = array[safe: indexPath.row] {
            cell.reloadData(data: model as Any)
            if (model.cellHeigth > CGFloat(0)) == false {
                let size = cell.contentView.systemLayoutSizeFitting(CGSize(width: YYScreenSize().width, height: 0), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
                model.cellHeigth = size.height
            }
        }

        return cell;
    }
cddjr commented 3 years ago

无论MVC还是MVVM-C,M都不应和V耦合