如何将adbannerview添加到UISplitviewController [英] how to add an adbannerview to a UISplitviewController

查看:97
本文介绍了如何将adbannerview添加到UISplitviewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用UISplitViewController创建了一个ipad应用程序,它在两个方向都起作用。现在我想为此应用程序添加横幅。我该怎么做呢?在界面构建器中,我只能向detailView添加一个portait横幅,它可以或多或少地工作,但是当我转动iPad并单击横幅时,它会以纵向模式而不是横向模式打开。并且横幅永远不会达到ipad-landscape模式的规定宽度。

I have made an ipad application using an UISplitViewController, which functions in both orientation. Now I want to add banners to this application. How do I do this? In interface builder I can only add a portait banner to the detailView, which works more or less, but when I turn the iPad and click the banner it opens in portrait mode instead of landscape mode. And the banner can never get the prescribed width for ipad-landscape mode.

尝试以编程方式执行此操作,它告诉我adbannerview的父级应该是UIViewController。

Trying to do it programmatically, it tells me that the parent of the adbannerview should be a UIViewController.

推荐答案

同样的问题让我疯了很久,直到找到iAdSuite样本。因此,要扩展Erran的答案:使用Apple的iAdSuite示例代码。

This same problem drove me nuts for ages until I found the iAdSuite sample. So, to expand on Erran's answer: Use the iAdSuite sample code from Apple.

使用故事板为自己创建一个工作拆分视图应用程序。

Get yourself a working split view app using storyboards.

包含iAd框架。

将BannerViewController.h和.m文件复制到您的应用程序。然后在AppDelegate.m中的application didFinishLaunching中复制iAdSuite的AppDelegate中的行,按照此处的最后一行:

Copy the BannerViewController.h and .m files to your app. Then in AppDelegate.m in "application didFinishLaunching" copy the line from iAdSuite's AppDelegate as per the last line here:

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
    splitViewController.delegate = (id)navigationController.topViewController;
    UINavigationController *masterNavigationController = splitViewController.viewControllers[0];

    _bannerViewController = [[BannerViewController alloc] initWithContentViewController:splitViewController];

在iPhone部分,你需要这一行:

In the section for iPhone you need this line:

_bannerViewController = [[BannerViewController alloc] initWithContentViewController:navigationController];

在return语句之前添加此

Just before the return statement add this

self.window.rootViewController = _bannerViewController;

将此项添加到.m

@implementation AppDelegate{
BannerViewController *_bannerViewController;}

#import "BannerViewController.h"

或者以您喜欢的方式创建bannerViewController属性。

Or create the bannerViewController property any way you prefer.

修改.h如下:

#import <UIKit/UIKit.h> 
@class BannerViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>

这足以让它全部运转。整个拆分视图应用程序现在在BannerView内部运行。它处理所有AdBannerDelegate函数。

That was enough to get it all working. The whole split view app now operates inside the BannerView. That handles all the AdBannerDelegate functions.

祝你好运: - )

这篇关于如何将adbannerview添加到UISplitviewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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