如何创建 adWhirl 单例以在所有视图控制器中使用 1 添加横幅

发布于 2024-12-23 12:31:05 字数 1020 浏览 1 评论 0原文

我整个晚上都在阅读,似乎要获得 adWhirl 广告,请在所有视图控制器中使用相同的添加横幅,我需要创建一个单例 awView 并在 ViewWillLoad 和 ViewWillLoad 中使用它。每个View的ViewWillUnload。

我很难让它发挥作用。我找到了大量的 AdWhirl 教程,但没有一个创建单例。

我目前有这个 adWhirlSingleton.h

#import <Foundation/Foundation.h>
#import "AdWhirlDelegateProtocol.h"
#import "AdWhirlView.h"

@interface adWhirlSingleton : NSObject <AdWhirlDelegate> {
    AdWhirlView *awView;
    UIViewController *primaryView;
}

@property (strong, nonatomic) AdWhirlView *awView;
@property (strong, nonatomic) UIViewController *primaryView;

@end

adWhirlSingleton.m

#import "adWhirlSingleton.h"

@implementation adWhirlSingleton
@synthesize primaryView, awView;

-(NSString *)adWhirlApplicationKey
{
    return @"my key here";
}

-(UIViewController *)viewControllerForPresentingModalView
{
    return primaryView;
}

@end

我将 adWhirlSingleton 导入到我的视图中,但是当我输入 adWhirlSingleton.primaryView = self 时,我无法识别 PrimaryView。

为了实现这个我还缺少什么? 谢谢

I've been reading all evening and it seems that to get an adWhirl ad use the same add banner across all view controllers, I need to create a singleton awView and use this in the ViewWillLoad & ViewWillUnload of each View.

I am having trouble getting this to work. I've found tons of AdWhirl tutorials but none that create a singleton.

I currently have this adWhirlSingleton.h

#import <Foundation/Foundation.h>
#import "AdWhirlDelegateProtocol.h"
#import "AdWhirlView.h"

@interface adWhirlSingleton : NSObject <AdWhirlDelegate> {
    AdWhirlView *awView;
    UIViewController *primaryView;
}

@property (strong, nonatomic) AdWhirlView *awView;
@property (strong, nonatomic) UIViewController *primaryView;

@end

adWhirlSingleton.m

#import "adWhirlSingleton.h"

@implementation adWhirlSingleton
@synthesize primaryView, awView;

-(NSString *)adWhirlApplicationKey
{
    return @"my key here";
}

-(UIViewController *)viewControllerForPresentingModalView
{
    return primaryView;
}

@end

I import adWhirlSingleton into my views, but when I type adWhirlSingleton.primaryView = self I doesn't recognize the primaryView.

What am I missing to implement this?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

会发光的星星闪亮亮i 2024-12-30 12:31:05

单例有一个工厂 init 方法(该方法将以 + 开头,而不是 -)来确保只创建一个。您可能还有其他事情正在发生,但是任何不使其自身成为单例的对象都不会成为单例。

这是有关创建单例的堆栈溢出问题,可能会有所帮助。这个也会给出示例还有一个很棒的< a href="http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html" rel="nofollow noreferrer">Matt Gallagher 的帖子他们。创建单例实例后,您将始终使用类似
的内容引用它
[[adWhirlSingleton 共享单例] PrimaryView]
如果您刚刚开始,应用程序委托是单例,因此如果您看到使用应用程序委托及其共享实例的演示代码,您将获得一些有关如何引用单例的示例。

Singletons have a factory init method (the method will start with a + instead of a -) to ensure that only one gets created. You may have other things going on, but any object that doesn't make itself a singleton won't be a singleton.

Here is a stack overflow question about creating singletons that might help. This one will also give examples There is also an excellent Matt Gallagher post about them. Once you create the singleton instance you will always reference it with something like
[[adWhirlSingleton sharedSingleton] primaryView]
If you've just been starting out, the Application Delegate is a singleton, so if you see demo code that uses the Application Delegate and its shared instance, you will have some examples for how to reference a singleton.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文