添加tableview作为子视图(如果你必须继承自UITableVC)
我想要的是一个表格视图,顶部有一个广告视图,用于 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让您的视图控制器继承
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-inview
, 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.source: I do this in my apps, and they are on the store.
有很多事情你可以尝试。
正如大家所说,您可以停止从
UITableViewController
继承。如果您使用 Culver 的PullRefreshTableViewController
,请将其调整为仅子类UIViewController
。您需要重新添加tableView
属性,并采用UITableViewDataSource
和UITableViewDelegate
协议(如果这样做)。您可以设置表格视图的
contentInset
以在顶部留出空间,并在控制器中定义scrollViewDidScroll:
以在每次滚动时适当地重新定位广告视图。 (UITableView
是UIScrollView
的子类,因此如果您定义了UIScrollViewDelegate
方法,它将调用它们。)There are lots of things you could try.
You could stop inheriting from
UITableViewController
, like everyone says. If you're using Culver'sPullRefreshTableViewController
, adapt it to just subclassUIViewController
. You'll need to add back thetableView
property, and adopt theUITableViewDataSource
andUITableViewDelegate
protocols if you do.You could set the
contentInset
of the table view to leave room at the top, and definescrollViewDidScroll:
in your controller to reposition the ad view appropriately on each scroll. (UITableView
subclassesUIScrollView
, so it will call theUIScrollViewDelegate
methods if you define them.)