【问题标题】:Last row on child view controller's table view cannot select子视图控制器的表格视图的最后一行无法选择
【发布时间】:2018-01-11 09:33:34
【问题描述】:

我正在尝试制作一个带有表格视图的视图容器。这很好,但是如果我选择最后一行,则无法触发方法didSelectRowAt indexPath:。这是我的代码:

    let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
    let controller = storyboard.instantiateViewController(withIdentifier: "pageViewController") as! PageViewController
    addChildViewController(controller)
    controller.customDelegate = self
    controller.index = index
    self.controller = controller
    //Add Controllers
    let clientInfoVC = storyboard.instantiateViewController(withIdentifier: "ClientInfo") as! ClientInfoViewController
    clientInfoVC.client = self.client
    let clientRequestsVC = storyboard.instantiateViewController(withIdentifier: "ClientRequests") as! ClientProductRequestViewController
    clientRequestsVC.client = self.client
    let clientDebtsVC = storyboard.instantiateViewController(withIdentifier: "ClientDebts") as! ClientDebtViewController
    clientDebtsVC.client = self.client
    controller.orderedViewControllers = [clientInfoVC,clientRequestsVC,clientDebtsVC]
    controller.view.frame = CGRect(x: 0, y: 0, width: self.clientContainerView.frame.width, height: self.clientContainerView.frame.height)
    self.clientContainerView.addSubview(controller.view)
    controller.didMove(toParentViewController: self)

这是我的容器视图:

我做错了什么? 请帮帮我

【问题讨论】:

  • 表格视图下的白框是什么?
  • 没什么,它有来自视图控制器的约束。只是一片空白
  • 我怀疑表格视图的区域小于覆盖单元格的区域。如果您将表格视图的视图裁剪到其边界,您可以证明这一点。 BTW:为什么你不使用容器视图来嵌入视图控制器?
  • 我正在使用嵌入视图,这是子视图。也许问题出在这个地区?
  • 我发现了错误,谢谢@macmoonshine

标签: ios uiviewcontroller childviews


【解决方案1】:

我找到了解决办法:

我需要删除控制器的框架设置,仅此而已。所以只需删除这一行:

    controller.view.frame = CGRect(x: 0, y: 0, width: self.clientContainerView.frame.width, 
                                             height: self.clientContainerView.frame.height)

【讨论】:

    猜你喜欢
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多