UITableViewController 作为子视图 swift

UITableViewController as subview swift

我正在尝试制作我的第一个应用程序,但遇到了困难。

我的应用看起来像 snapchat,水平滚动视图,左侧部分由 table 视图组成。 所以,在这个左边部分,我把 tableViewController 作为子视图。问题是细胞总是空的! table 视图显示了正确的单元格高度,但单元格是空的。

我相信你能帮助我,谢谢!

I make the subview here

Link with cells here

我知道这不是您问题的答案,但我有一个建议可能会长期帮助您 运行,并且可能会帮助您调试当前的问题:
将 tableView 的逻辑拆分成单独的 UITableViewController 怎么样?这样你就可以避免一些巨大的常见 UIViewController。您可以在情节提要中使用 Container View,它可以嵌入 UIViewController.

请确保覆盖 table 视图控制器中的必要方法并在添加子视图控制器代码时平衡调用 rutin.One 添加子视图控制器时最后一件事你应该为控制器视图提供正确的大小.

用于添加 table 视图控制器作为子视图控制器

 guard let list = R.storyboard.dashboard.addressesController()else {
      return
    }

    self.list = list

    self.addChildViewController(list)
    self.scroll.addSubview(list.view)
    list.didMoveToParentViewController(self)

    list.tableView.layoutIfNeeded()

    list.view.snp_makeConstraints(closure: {
      (make) in
      make.left.equalTo(self.view).offset(10)
      make.right.equalTo(self.view).offset(-10)
      make.bottom.equalTo(self.scroll)
      make.height.equalTo(list.tableView.contentSize.height)
      make.top.equalTo(authorizedTop.snp_bottom).offset(10)
    })

用于扩展 table 视图控制器

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier(self.cellIdentifier) as UITableViewCell

        cell.textLabel?.text = self.tableData[indexPath.row]

        return cell
    }