简体   繁体   English

在其静态单元格中具有动态 tableview 的 Tableview Controller

[英]Tableview Controller with a dynamic tableview in its static cell

I have a form inside a tableview controller.我在 tableview 控制器中有一个表单。 The last 3 parts of the form are address textfield, map and a save button.表单的最后 3 部分是地址文本字段、地图和保存按钮。 When the user begins typing on the address field a uitableview will slide up covering the map to display different results.当用户开始在地址字段上输入时,uitableview 将向上滑动覆盖地图以显示不同的结果。 When I set the child tableview mapTableview's delegate and datasource to self this is when the problem would start, the screen just displays a white background.当我将子 tableview mapTableview 的委托和数据源设置为 self 时,这是问题开始的时候,屏幕只显示白色背景。 I tried different solutions but they don't work.我尝试了不同的解决方案,但它们不起作用。 Also tried this one but the data source must be coming from the tableview controller itself.也试过这个,但数据源必须来自 tableview 控制器本身。 Dynamic Tableview inside a Static tableview Cell 静态表格视图单元格内的动态表格视图

When I create an array of strings in the class Datasource and put the following codes below in my tableview controller, the strings get displayed in the mapTableView.当我在类 Datasource 中创建一个字符串数组并将以下代码放在我的 tableview 控制器中时,这些字符串将显示在 mapTableView 中。

    var dataSource = DataSource() 


    mapTableView.delegate = dataSource
    maptTableView.delegate = dataSource 

But since the data source must be coming from tableview controller, I tried to put the code below, and many other things as suggested in other posts, in my table view controller but the screen won't display anything, just all white.但是由于数据源必须来自 tableview 控制器,我尝试将下面的代码以及其他帖子中建议的许多其他内容放在我的 table view 控制器中,但屏幕不会显示任何内容,只是全白。 And I get these errors:我收到这些错误:


UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window) UITableView 被告知在不在视图层次结构中布局其可见单元格和其他内容(表视图或其超视图之一尚未添加到窗口中)


Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view.检测到约束模糊地建议表格视图单元格的内容视图的高度为零的情况。 We're considering the collapse unintentional and using standard height instead我们正在考虑无意识的坍塌并使用标准高度


    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
     }
 }

and in my viewDidLoad在我看来DidLoad

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

How to correctly put a tableview inside a static tableview cell?如何正确地将 tableview 放入静态 tableview 单元格中? Please help请帮忙

  1. You should create another table view controller for the inner table view.您应该为内部表视图创建另一个表视图控制器。 Let's call it MapTableViewController .我们称之为MapTableViewController
  2. Add Container View into the static cell in storyboard.Container View添加到故事板的静态单元格中。
  3. Add Table View Controller into that container view, set its class to MapTableViewController .Table View Controller添加到该容器视图中,将其类设置为MapTableViewController
  4. Put all datasource/delegate methods for mapTableView from the EditProfileTableViewController into MapTableViewController .将所有用于mapTableView数据源/委托方法从EditProfileTableViewController放入MapTableViewController After that, EditProfileTableViewController should have no UITableViewDataSource and UITableViewDelegate protocol methods at all.之后, EditProfileTableViewController应该根本没有UITableViewDataSourceUITableViewDelegate协议方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM