简体   繁体   English

将顶部/底部视图添加到 UITableViewController?

[英]Add top/bottom views to UITableViewController?

In my storyboard I have UITableViewController which has custom class.在我的故事板中,我有 UITableViewController,它具有自定义类。 How can I add UIView objects on top and bottom parts of the table view?如何在表格视图的顶部和底部添加 UIView 对象?

Do I have to create UITableView and two desired views inside of UIView and then manually init my controller, set tableView or there is a better way?我是否必须在 UIView 中创建 UITableView 和两个所需的视图,然后手动初始化我的控制器,设置 tableView 还是有更好的方法?

If you're wanting to use UITableViewController for it's abilities to manage cells and static layouts, the best possibility would be to use a container view in your storyboard.如果您想使用 UITableViewController 来管理单元格和静态布局,最好的方法是在故事板中使用容器视图。 This would allow you to layout the main view contents around the table and still keep a separate UITableViewController maintaining the table itself.这将允许您围绕表格布局主视图内容,并且仍然保留一个单独的 UITableViewController 维护表格本身。 Set up the right auto layout constraints (really simple, just anchor the container view to the header and footer views)设置正确的自动布局约束(非常简单,只需将容器视图锚定到页眉和页脚视图)

在此处输入图片说明

Yes it's possible in UITableViewConroller:是的,在 UITableViewConroller 中是可能的:

    let bottomView = UIView()
    bottomView.backgroundColor = .red // or your color
    bottomView.frame = CGRect(x: 0, y: UIScreen.main.bounds.size.height - 78, width: tableView.frame.size.width, height: 78) // 78 or your size of view
    navigationController?.view.addSubview(bottomView)
    tableView.tableFooterView = UIView()

在此处输入图片说明

Something like this should work for you:这样的事情应该适合你:

// Your frame/view will vary
UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(0, 64, 320, 44)];
subview.backgroundColor = [UIColor redColor];

[self.navigationController.view addSubview:subview];

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

相关问题 顶部和底部的UITableViewController SafeAreaLayout - UITableViewController SafeAreaLayout for Top & Bottom 删除Uitableviewcontroller上托管的Uitableview顶部或底部的视图? - Remove view on top or bottom of Uitableview hosted on Uitableviewcontroller? 在uitableviewcontroller顶部添加新对象 - add new object at the top of uitableviewcontroller 在 UITableViewController (Swift) 顶部添加按钮 - Add button on top of UITableViewController (Swift) 如何在Storyboards中将工具栏添加到UITableViewController的底部? - How to add a toolbar to the bottom of a UITableViewController in Storyboards? 在Swift中的UITableViewController顶部添加一个UIView - Add a UIView over the top of UITableViewController in Swift 初学者:如何在UITableViewController上添加带按钮的顶栏 - Beginner: How to add top bar with buttons on UITableViewController 如何将底部安全区域添加到 Static UITableviewController? 不在 UITableview - How to Add Bottom Safe Areal to Static UITableviewController ? Not in UITableview 如何在UITableViewController顶部的标题中添加按钮和搜索栏? - How to add buttons and search bar into header at top of UITableViewController? 在UITableViewController的底部锚定视图 - Anchor a view at the bottom of a UITableViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM