【问题标题】:add a table view to a table view cell in swift快速将表格视图添加到表格视图单元格
【发布时间】:2019-04-18 22:26:21
【问题描述】:

我想实现这种类型的屏幕。有两个表格视图,一个在右侧,另一个在左侧。在左侧表(chatOne)视图中,我想在其第一部分(即 chatOneCell)中添加一个表视图。

如何快速将表格视图添加到表格视图单元格?

我正在尝试将表格视图添加到表格视图单元格。外部表显示成功。但内部表未加载。如果我要添加视图、按钮标签等。它显示在单元格中,但不显示在表格视图中。请查看我的代码并帮助我纠正我的问题

ChatOne 是外部表格视图的单元格

InerTable 是我试图在 chatOne Cell 中放置的表格

insideCell 是 inerTable 的单元格

iner table 有标签 45,ouer 有标签 25

        class ChatOne: UITableViewCell{

            @IBOutlet weak var inerTable: UITableView!


            override func awakeFromNib() {
                super.awakeFromNib()


                inerTable.dataSource = self as? UITableViewDataSource
                inerTable.delegate = self as? UITableViewDelegate
               inerTable.reloadData()

            }

           }

        class insideCell: UITableViewCell {
            @IBOutlet weak var myLabel: UILabel!
            override func awakeFromNib() {
                super.awakeFromNib()

            }
        }



        public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                if tableView.tag == 45{
                    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! insideCell
                    cell.myLabel.text = "Tapan"
                    return cell
                }
                if tableView.tag == 25{

                    let rowIdentifier = tableOneIdentifire[indexPath.section]
                    let cell = tableView.dequeueReusableCell(withIdentifier: rowIdentifier)
                    return cell!
                }


                return UITableViewCell()

            }

【问题讨论】:

  • 你需要在ChatOne calss中实现tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {} 方法并返回InerTable数据源计数。为什么你的 cellForRowAt 方法不在 ChatOne 类中?
  • 必须在包含表视图的 ChatOne 类中添加表视图 dataSource 和委托方法。
  • 你实现了内表的委托吗?
  • 你也能分享一下为什么你需要表内表吗?也许有更简单的方法
  • 1. class ChatOne: UITableViewCell, UITableViewDelegate, UITableViewDataSource 2.实现表间委托

标签: swift uitableview


【解决方案1】:

我在 swift 中添加表格视图时也遇到了这种问题。所以我点击这个链接,所有细节都清楚。所以请关注shorturl.at/yKSYZ

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    相关资源
    最近更新 更多