【问题标题】:Tableview Controller with a dynamic tableview in its static cellTableview 控制器在其静态单元格中具有动态 tableview
【发布时间】:2020-02-13 02:11:41
【问题描述】:

我在 tableview 控制器中有一个表单。表单的最后 3 部分是地址文本字段、地图和保存按钮。当用户开始在地址字段上键入时,uitableview 将向上滑动覆盖地图以显示不同的结果。当我将子 tableview mapTableview 的委托和数据源设置为 self 时,这就是问题开始的时候,屏幕只显示白色背景。我尝试了不同的解决方案,但它们不起作用。也试过这个,但数据源必须来自 tableview 控制器本身。 Dynamic Tableview inside a Static tableview Cell

当我在 Datasource 类中创建一个字符串数组并将以下代码放在我的 tableview 控制器中时,这些字符串将显示在 mapTableView 中。

    var dataSource = DataSource() 


    mapTableView.delegate = dataSource
    maptTableView.delegate = dataSource 

但由于数据源必须来自 tableview 控制器,我尝试将下面的代码以及其他帖子中建议的许多其他内容放在我的 table view 控制器中,但屏幕不会显示任何内容,只是全白.我得到了这些错误:


UITableView 被告知在不位于视图层次结构中的情况下布局其可见单元格和其他内容(表格视图或其父视图之一尚未添加到窗口中)


检测到约束模糊地建议表格视图单元格的内容视图高度为零的情况。我们正在考虑意外折叠并改用标准高度


    extension EditProfileTableViewController {

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}


override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
          return pois.count
      }

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       let cell = tableView.dequeueReusableCell(withIdentifier: "cellResult", for: indexPath) as! MapTableViewCell

       let poi = pois[indexPath.row]

       cell.textLabel?.text = poi.title
       cell.detailTextLabel?.text = poi.subtitle
       cell.detailTextLabel?.numberOfLines = 0

       return cell
     }
 }

在我看来DidLoad

tableView.estimatedRowHeight = 60.0;
tableView.rowHeight = UITableView.automaticDimension;

如何正确地将 tableview 放入静态 tableview 单元格中?请帮忙

【问题讨论】:

    标签: ios uitableview swift5


    【解决方案1】:
    1. 您应该为内部表视图创建另一个表视图控制器。我们就叫它MapTableViewController吧。
    2. Container View 添加到情节提要的静态单元格中。
    3. Table View Controller 添加到该容器视图中,将其类设置为MapTableViewController
    4. mapTableView 的所有数据源/委托方法从EditProfileTableViewController 放入MapTableViewController。之后,EditProfileTableViewController 应该完全没有 UITableViewDataSourceUITableViewDelegate 协议方法。

    【讨论】:

    • 嗨,尤金,感谢您的回复。我会试试你的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    • 2015-10-02
    相关资源
    最近更新 更多