iAd在UINavigationController中的UITableViewController下面 [英] iAd below UITableViewController inside UINavigationController

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

问题描述

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



我有一个带UITableViewController的UINavigationController,因为它的根视图。



我把它放在一个故事板中没问题,但我试图将iAd视图拖到屏幕底部,xcode不允许我添加它。



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



<这对我来说似乎不对。我只想尝试UITableView的文章标题,顶部有一个导航栏,底部有一个iAd ...



建议?建议?



提前致谢。

解决方案

最简单的一个实现此目的的方法是使用 UITableView tableFooterView 属性。是的,我知道页脚停留在桌子的底部,但它没有。您可以在表格中设置其框架。像这样添加iAd作为页脚:

  self.tableView.tableFooterView = iAd; 

然后,要在表格滚动时调整iAd的框架,请执行 UIScrollView 委托方法:(这是可能的,因为 UITableView 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帧的下行距离。


I'm building an app for a blog site.

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

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.

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.

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...

Advice? Suggestions?

Thanks in advance.

解决方案

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; 

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;
}

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.

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

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