UITableViewCell嵌套UITableView的正确姿势

来源:互联网 发布:简易个人博客php源码 编辑:程序博客网 时间:2024/05/16 10:12

        内嵌UiTableView的高度计算起来太麻烦了,如何解决,就是把二级TableVIew里面的model item做到一级,然后对不同的item类型做不同的Cell,这样就Ok了。给一个得到Cell的源码供大家参考

override func tableView(_ tableView: UITableView,                            cellForRowAt indexPath: IndexPath) -> UITableViewCell {        // Get a new or recycled cell        let item = tableItems[indexPath.row]        if type(of: item) == Review.self{            let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewCell",                                                     for: indexPath) as! ReviewCell            cell.review = item as! Review            cell.updateViews()            return cell                    }else{            let cell = tableView.dequeueReusableCell(withIdentifier: "ReplyCell",                                                     for: indexPath) as! ReplyCell            cell.reply = item as! Reply            cell.updateViews()            return cell                    }                            }


       参考:https://segmentfault.com/q/1010000005595959