添加tableview作为子视图(如果你必须继承自UITableVC)

发布于 2025-01-06 14:01:07 字数 620 浏览 3 评论 0原文

我想要的是一个表格视图,顶部有一个广告视图,用于 admob 和拉动刷新。现在我正在使用 tableheaderview,但它会滚动,我需要广告持续存在。 viewforheader 不滚动,但摆脱了节标题所需的标准标题。如果我继承自 tableVC,是否可以重写 loadview 以构建静态视图来保存广告,然后将 tableview 置于其下方?我尝试编写 loadview 并且可以获得广告,但是在尝试 tableview 时,我在控制台中收到“无法恢复选定的帧”。我正在使用卡尔弗的拉动刷新技术,因为它非常容易实现。我知道 tableVC 假设根视图是 tableview 那么我该如何解决这个问题呢?网上的每个解决方案都说使用标准的 uiviewcontroller,但我卡住了,因为拉动刷新

这是在我的加载视图中:

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, 320, 400) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;

[self.view addSubview:self.tableView];

What I want is a tableview with an ad view on top for admob and pull to refresh. Right now i'm using the tableheaderview, but that scrolls and I need the ad to persist. viewforheader doesn't scroll, but gets rid of the standard headers that i need for the section headers. if im inheriting from a tableVC, is there anyway to override loadview to build a static view to hold an ad and then have the tableview below that? i've tried writing loadview and can get the ad, but when trying the tableview, i get "unable to restore selected frame" in the console. i'm using culver's pull to refresh technique as its very simple to implement. i know a tableVC assumes the root view is a tableview so how can i get around that? every solution on the net says use a standard uiviewcontroller, but im stuck cause of the pull to refresh

this is in my loadview:

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, 320, 400) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;

[self.view addSubview:self.tableView];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望喜 2025-01-13 14:01:07

让您的视图控制器继承 UIViewController,但继续实现 。将 TableView 添加为 UIViewController 内置 view 的子视图,指向数据源和委托的文件所有者。使表格视图小于高度的 100%,并将广告作为主视图中的另一个视图,使其显示在表格下方/上方。

在此处输入图像描述

来源:我在我的应用程序中执行此操作,它们在商店中。

Make your view controller inherit from UIViewController, but continue to implement <UITableViewDataSource, UITableViewDelegate>. Add your TableView as a sub-view of the UIViewController's built-in view, pointing to File's Owner for data source and delegate. Make the table view less than 100% of the height, and have the ad as another view within the main view that makes it appear below/above the table.

enter image description here

source: I do this in my apps, and they are on the store.

树深时见影 2025-01-13 14:01:07

有很多事情你可以尝试。

正如大家所说,您可以停止从 UITableViewController 继承。如果您使用 Culver 的 PullRefreshTableViewController,请将其调整为仅子类 UIViewController。您需要重新添加 tableView 属性,并采用 UITableViewDataSourceUITableViewDelegate 协议(如果这样做)。

您可以设置表格视图的 contentInset 以在顶部留出空间,并在控制器中定义 scrollViewDidScroll: 以在每次滚动时适当地重新定位广告视图。 (UITableViewUIScrollView 的子类,因此如果您定义了 UIScrollViewDelegate 方法,它将调用它们。)

There are lots of things you could try.

You could stop inheriting from UITableViewController, like everyone says. If you're using Culver's PullRefreshTableViewController, adapt it to just subclass UIViewController. You'll need to add back the tableView property, and adopt the UITableViewDataSource and UITableViewDelegate protocols if you do.

You could set the contentInset of the table view to leave room at the top, and define scrollViewDidScroll: in your controller to reposition the ad view appropriately on each scroll. (UITableView subclasses UIScrollView, so it will call the UIScrollViewDelegate methods if you define them.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文