将可点击和固定的子视图添加到UITableViewController? [英] Add clickable and fixed subview to UITableViewController?

查看:144
本文介绍了将可点击和固定的子视图添加到UITableViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想静态地将ADBannerView对象放在我的UITableView屏幕上,这意味着我希望它始终保持在我的工具栏上方(self.navigationController.toolbar),即使用户正在滚动tableview。我已经通过将ADBannerView作为子视图添加到我的工具栏中来解决这个问题,并给出了帧原点的负值:

I'd like to place an ADBannerView object onto my UITableView screen statically, what means that I want it to always stay above my toolbar (self.navigationController.toolbar), even when the user is scrolling the tableview. I've solved this by adding by ADBannerView as a subview to my toolbar and given it negative values for the frames origin:

[self setBannerViewSize];
[self.navigationController.toolbar addSubview:bannerView];

唯一的问题是:我无法点击并以这种方式打开iAd - 我可以看到横幅但是当我点击它时没有任何反应。

The only problem is: I can't click and open the iAd this way - I can see the banner but nothing happens when I tap on it.

因为我也使用了refreshControl,所以选择使用UIViewController而不是UITableViewController并手动添加tableView为我工作。有没有其他方法可以让我的ADBannerView静态显示在我的表格视图控制器中并且仍然可以点击?

Since I'm also using a refreshControl, the option to use a UIViewController instead of UITableViewController and add a tableView manually wouldn't work for me. Is there any other way I can get my ADBannerView statically showing in my table view controller AND still being tappable?

谢谢你的建议!

推荐答案

耶!毕竟我自己成功地解决了这个(非常烦人的)问题(还有很多阅读)!

Yay!! After all I succeeded in solving this (really annoying) problem by myself (and a lot of reading around)!

首先,我发现这真的是改变世界的帖子。基本上这个帖子处理的主题是UITableViewController使用self.view作为其tableView属性,因此覆盖tableView属性(或手动合成),并给self.view一个新视图(来自应用程序)并添加tableView作为其子视图将使有可能到达tableView的真正的超级视图。

First, I found this really world-changing post. Basically this post handles with the topic that a UITableViewController uses self.view for its tableView property, so overriding the tableView property (or synthesizing it manually) plus giving self.view a new view (from application) and adding tableView as its subview would make it possible to reach the real superview of tableView.

但这仍然没有解决我的问题,虽然我确信它会,因为这一切都有道理。我的bannerView出现在正确的位置(并且已修复)但点击时仍然没有做任何事情。但是还有一件我不知道的小事:

But this still didn't solve my problem, although I was sure it would, because it all made sense. My bannerView appeared in the right place (and was fixed) but it still didn't do anything when clicked. But there was a second minor thing I didn't know about:

当我读到这篇文章子视图的超级视图不仅必须是userInteractionEnabled,还要有一个不透明的backgroundColor。因为我的超级视图背景颜色设置为[UIColor clearColor],所有这些都不起作用 - 但将其backGroundColor设置为例如blackColor解决了整个问题:bannerView终于可以点击了! :)

As I read in this post the superview of a subview doesn't only have to be userInteractionEnabled but also have a non-transparent backgroundColor. Because my superviews background color was set to [UIColor clearColor] it all didn't work - but setting its backGroundColor to e.g. blackColor solved the whole problem: the bannerView got finally tappable! :)

所以,我的代码现在看起来像这样:

So, my code is now looking like this:

@synthesize tableView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    if (!tableView && [self.view isKindOfClass:[UITableView class]]) {
        tableView = (UITableView *)self.view;
    }

    self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    self.tableView.frame = self.view.bounds;
    [self.view addSubview:self.tableView];

    [self resizeTableToFitBanner];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bannerView];

    // some other code
}

这篇关于将可点击和固定的子视图添加到UITableViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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