使用故事板将 UIView 添加到 UITableViewController

Add UIView to UITableViewController with Storyboards

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

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

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

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)
        ])

}