【问题标题】:Add UIView to UITableViewController with Storyboards使用 Storyboard 将 UIView 添加到 UITableViewController
【发布时间】:2017-05-13 22:12:00
【问题描述】:

在我的应用程序中,我需要将 UIView 添加到我的 UITableViewController。现在,它只允许我将它添加到现有的表格视图中。我想要的是将 UIView 添加到我的 UITableViewController 中。有人可以帮我解决这个问题吗?谢谢!

【问题讨论】:

  • 在 UITableViewController 中,UITableView 是根视图,因此没有“tableview 之外”可以添加另一个视图的地方
  • 能否详细解释一下,能否提供一些图纸?
  • UITableViewControllerUIViewController 的子类。视图控制器有一个 view 属性,它是根视图。您可以向该视图添加子视图,但不能在其上方添加视图,因为它是根。在一个 UITableViewController 中,tableview 是根视图,所以只能给 tableview 添加视图。

标签: ios interface-builder uistoryboard


【解决方案1】:

您可以使用 UIViewController,然后您将能够添加 UITableView 和 UIView 。如果使用 UITableViewController,则不能在其中添加 UIView

【讨论】:

【解决方案2】:

您可以通过编程方式完成此任务。

viewDidLoad()方法中添加这段代码:

func setupBottomView() {
    bottomView = BottomView(frame: .zero)

    view.addSubview(bottomView)

    bottomView.translatesAutoresizingMaskIntoConstraints = false

    // Constraint Layout
    NSLayoutConstraint.activate([
        bottomView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0),
        bottomView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 0),
        bottomView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: 0),
        bottomView.heightAnchor.constraint(equalToConstant: 120)
        ])

}

【讨论】:

    猜你喜欢
    • 2012-01-17
    • 2013-07-14
    • 2013-09-14
    • 1970-01-01
    • 2012-05-12
    • 2020-03-18
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多