UINavigationController 内的 UITableViewController 下面的 iAd [英] iAd below UITableViewController inside UINavigationController

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

问题描述

我正在为博客网站构建一个应用程序.

I'm building an app for a blog site.

我有一个 UINavigationController 和一个 UITableViewController 作为它的根视图.

I have a UINavigationController with a UITableViewController as it's root view.

我把它放在情节提要中没问题,但我试图将 iAd 视图拖到屏幕底部,xcode 不允许我添加它.

I laid this out in a storyboard no problem, but I'm trying to drag an iAd view to the bottom of the screen and xcode will not let me add it.

看起来我必须从 UITableViewController 的子类切换到 UIViewController 的子类,然后将我的委托和数据源方法放在我的子类 UIViewController 中.

It looks like I have to switch from a subclass of UITableViewController to a subclass of UIViewController, and just put my delegate and datasource methods in my subclassed UIViewController.

这对我来说似乎是错误的.我只是想以文章标题的 UITableView 结束,顶部有一个导航栏,底部有一个 iAd...

This seems wrong to me. I'm just trying to end up with a UITableView of article headlines, with a navbar up top, and an iAd at the bottom...

建议?有什么建议吗?

提前致谢.

推荐答案

完成此任务的最简单方法之一是使用 UITableViewtableFooterView 属性.是的,我知道页脚位于表格的底部,但并非必须如此.您可以在表格中设置其框架.像这样添加 iAd 作为页脚:

One of the easiest ways to accomplish this is using the UITableView's tableFooterView property. Yes, I know the footer stays at the bottom of the table, but it doesn't have to. You can set its frame within the table. Add the iAd as the footer like so:

self.tableView.tableFooterView = iAd; 

然后,要在表格滚动时调整 iAd 的框架,请实现 UIScrollView 委托方法:(这是可能的,因为 UITableView 的子类UIScrollView)

Then, to adjust the frame of the iAd as the table scrolls, implement the UIScrollView delegate method: (This is possible because UITableView is a subclass of UIScrollView)

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGRect iAdFrame = iAd.frame;
    CGFloat newOriginY = table.contentOffset.y + table.frame.size.height - iAdFrame.size.height;
    CGRect newIAdFrame = CGRectMake(iAdFrame.origin.x, newOriginY, iAdFrame.size.width, iAdFrame.size.height);
    iAd.frame = newIAdFrame;
}

您可以看到实现非常简单.我们只需使用 contentOffset y 来确定 iAd 的框架应该向下多远.

You can see that the implementation is easy enough. We simply use the contentOffset y to determine how far down the frame of the iAd should be.

这篇关于UINavigationController 内的 UITableViewController 下面的 iAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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