在Swift 3的tableview单元内可以实现tableview吗? [英] Is it possible to implement tableview inside tableview cell in swift 3?

查看:72
本文介绍了在Swift 3的tableview单元内可以实现tableview吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将表视图放入uitableview单元格时遇到麻烦.现在,我将执行评论并回复.并且回复应该在其中您要发表评论的地方. 因此,我将在tableview单元中实现发布评论,在其中回复其他tableview单元中所有评论. 任何建议或其他方式来实现这些方案!

I'm having trouble with putting a tableview inside a uitableview cell. right now I am going to implement the comments and reply. and reply should be inside which you are going to comments. so I am going to implement comments of post in tableview cell, inside it reply of all that comments in other tableview cell. Any suggestion or other way to implement these scenario!

推荐答案

第一种方法:

  1. 为子tableView创建一个子类,并覆盖internalContentSize.

  1. Create a subclass for child tableView and override intrinsicContentSize.

     class MyOwnTableView: UITableView {
    override var intrinsicContentSize: CGSize {
        self.layoutIfNeeded()
        return self.contentSize
    }

    override var contentSize: CGSize {
        didSet{
            self.invalidateIntrinsicContentSize()
        }
    }

    override func reloadData() {
        super.reloadData()
        self.invalidateIntrinsicContentSize()
    }
}

  • 在接口"构建器中,将子tableView的类更改为MyOwnTableView(UITableView的子类).

  • In Interface builder change the class of your child tableView to MyOwnTableView (subclass of UITableView).

    设置父表视图和子表视图的自动行高.

    Set automatic row height for both the parent and child table view.

        tableView.estimatedRowHeight = 60.0;
        tableView.rowHeight = UITableViewAutomaticDimension;
    

  • 第二种方法: 1.为子tableView创建一个具有任何值的高度约束,并连接设置子tableView高度的IBOutlet. 2.将高度约束的常量设置为tableView.contentSize.height

    Second Approach: 1. Create a height constraint with any value for child tableView and conect an IBOutlet that sets the child tableView height. 2. Set the height constraint's constant to tableView.contentSize.height

        self.tableViewHeight.constant = self.tableView.contentSize.height
    

    这篇关于在Swift 3的tableview单元内可以实现tableview吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆