固定标题到 UITableview? [英] Fixed header to UITableview?

查看:21
本文介绍了固定标题到 UITableview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView,我想在它上面放置一个 44 像素的子视图.我尝试了 tableViewHeader,但它会随着表格的其余部分滚动.

I've got a UITableView that I'd like to stick a 44px subview on top of. I tried tableViewHeader, but that scrolls with the rest of the table.

我尝试搜索,发现很多人说我需要添加一个 UIView 超级视图,然后将我的标题和 UITableView 添加到其中.但是,我找不到有关如何执行此操作的示例.我尝试创建一个新的 UIView 子类并在 IB 中布置子视图,但是我在让表控制器与 UITable 链接时遇到了麻烦(因为我对 IB 不够了解).

I tried searching and have found many people saying I need to add a UIView superview and then add my header and the UITableView to it. However I can't find an example on exactly how to do this. I tried making a new UIView subclass and laying out the subviews in IB, but I ran into trouble getting the table controller to link w/ the UITable (because I don't know enough about IB).

我怎样才能使用 XIB 做到这一点?有人能举个例子吗?

How can I do this with XIBs? Can someone provide an example?

感谢你们提供的任何帮助.

Thanks for any help you guys can provide.

推荐答案

我终于在发帖后想通了.数据.:)

I finally figured this out right after posting. Figures. :)

这是我所做的,以防其他人遇到同样的问题:

Here's what I did, in case others run into the same problem:

  1. 删除现有的 UITableViewController 及其 XIB.他们是垃圾.当你这样做的时候真的很生气.

  1. Delete the existing UITableViewController and its XIB. They're junk. Get really mad while you do.

使用 XIB 创建一个新的 UIViewController 子类

Make a new UIViewController subclass with a XIB

在 IB 中打开 XIB 并将您的标题和 UITableView 添加到 UIView

Open XIB in IB and add your header stuff and a UITableView to the UIView

UITableView 的 IB Outlets 中,确保将 Delegate 和 DataSource 连接到文件所有者

In the IB Outlets for UITableView make sure you connect Delegate and DataSource to your File Owner

在你的视图控制器的头部,一定要添加来实现这些协议

In the header for your view controller, be sure to add <UITableViewDelegate, UITableViewDataSource> to implement these protocols

实现所有你熟悉和喜爱的常规 UITableView 委托和数据源方法,但在你的 UIViewController 中而不是你习惯的方式通过 UITableViewController

Implement all the regular UITableView delegate and data source methods you know and love, but in your UIViewController instead of the way you're used to doing it through UITableViewController

在这之后事情应该可以工作了.

After this things should work.

这篇关于固定标题到 UITableview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆