首页 > 代码库 > UITableViewCell嵌套UITableView的正确姿势
UITableViewCell嵌套UITableView的正确姿势
内嵌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
UITableViewCell嵌套UITableView的正确姿势
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。