iphone:基于最难的导航中不显示 iad 横幅?
我已经浏览了 bees4honey、iadsuites 示例(全部三个)以及每个人最喜欢的 raywenderlich 导师。他们都没有帮我展示横幅。我没有大多数导师通常提到的 xib。这是我的委托代码,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
// Create the window object
UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Assign the localWindow to the AppDelegate window, then release the local window
self.window = localWindow;
[localWindow release];
// Setup the first view controller
HomeViewController *homeViewController = [[HomeViewController alloc] init];
// Initialise the navigation controller with the first view controller as its root view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor blackColor]];
//[navigationController setNavigationBarHidden:YES];
[HomeViewController release];
// Add the navigation controller as a subview of our window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
我有 HomeViewController(用于导航和方法)和 HomeView(用于子视图)。 我的 homeviewcontroller.m
#pragma mark -
#pragma mark Initialisation
- (id)init {
self = [super init];
if (self) {
self.title = @"Home";
UIView *homeView = [[HomeView alloc] initWithParentViewController:self];
self.view = homeView;
[homeView release];
}
return self;
}
#pragma mark -
#pragma mark Action Methods
- (void)button3Action {...........rest of code below as method for the button located in HomeView.m
示例代码 来自 Homeview.m 的
// Private Methods
@interface HomeView()
- (void)loadButton3;
@end
@implementation HomeView
#pragma mark -
#pragma mark Initialization
- (id)initWithParentViewController:(HomeViewController *)parent {
if ((self = [super init])) {
// Update this to initialize the view with your own frame size
// The design has specified that there is to be no status bar present,
// please hide the status bar.
[self setFrame:CGRectMake(0, 0, 320, 480)];
// Assign the reference back to the parent view controller
refParentViewController = parent;
// Set the view background color
[self setBackgroundColor:[UIColor lightGrayColor]];
// Load subview methods
[self loadButton3];
}
return self;
}
#pragma mark -
#pragma mark Load Subview Methods
- (void)loadButton3 {
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button3 setTitle:@"Is that counterfeit product?" forState:UIControlStateNormal];
[button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button3 setBackgroundColor:[UIColor clearColor]];
button3.titleLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:25];
[button3 addTarget:refParentViewController action:@selector(button3Action) forControlEvents:UIControlEventTouchUpInside];
[button3 setFrame:CGRectMake(5, 375, 310, 31)];
[self addSubview:button3];
}
示例如果有人可以帮助我找出我需要在项目中放置“苹果批准的代码”以显示横幅的确切位置,那就太好了。
谢谢=)
I already went through bees4honey, iadsuites samples (all three of them), and everyone's favorite raywenderlich tutor. None of them helped me display the banner. I dont have any xib which most of the tutors usually mention. This is my delegate code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
// Create the window object
UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Assign the localWindow to the AppDelegate window, then release the local window
self.window = localWindow;
[localWindow release];
// Setup the first view controller
HomeViewController *homeViewController = [[HomeViewController alloc] init];
// Initialise the navigation controller with the first view controller as its root view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController.navigationBar setTintColor:[UIColor blackColor]];
//[navigationController setNavigationBarHidden:YES];
[HomeViewController release];
// Add the navigation controller as a subview of our window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
I have HomeViewController(for navigation and methods) and HomeView (for the subviews).
sample of my homeviewcontroller.m
#pragma mark -
#pragma mark Initialisation
- (id)init {
self = [super init];
if (self) {
self.title = @"Home";
UIView *homeView = [[HomeView alloc] initWithParentViewController:self];
self.view = homeView;
[homeView release];
}
return self;
}
#pragma mark -
#pragma mark Action Methods
- (void)button3Action {...........rest of code below as method for the button located in HomeView.m
sample code from Homeview.m
// Private Methods
@interface HomeView()
- (void)loadButton3;
@end
@implementation HomeView
#pragma mark -
#pragma mark Initialization
- (id)initWithParentViewController:(HomeViewController *)parent {
if ((self = [super init])) {
// Update this to initialize the view with your own frame size
// The design has specified that there is to be no status bar present,
// please hide the status bar.
[self setFrame:CGRectMake(0, 0, 320, 480)];
// Assign the reference back to the parent view controller
refParentViewController = parent;
// Set the view background color
[self setBackgroundColor:[UIColor lightGrayColor]];
// Load subview methods
[self loadButton3];
}
return self;
}
#pragma mark -
#pragma mark Load Subview Methods
- (void)loadButton3 {
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button3 setTitle:@"Is that counterfeit product?" forState:UIControlStateNormal];
[button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button3 setBackgroundColor:[UIColor clearColor]];
button3.titleLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:25];
[button3 addTarget:refParentViewController action:@selector(button3Action) forControlEvents:UIControlEventTouchUpInside];
[button3 setFrame:CGRectMake(5, 375, 310, 31)];
[self addSubview:button3];
}
it would be great if someone can help me find out where exactly I need to put the "apple approved code" in my project to display the banner.
Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的答案 ADBannerNavigation 中 Apple 的代码,您可以将其精简为检查广告显示的必要部分。我的意思是:
1)采用应用程序委托中的代码,定义 iAd 和 SharedADBannerView,并在 appdelegate.m 中:
2)因此,当您的控制器进入视图时,该实例就存在,您只需在 viewDidAppear Apple 的代码中添加即可但将原点更改为可见的东西(苹果建议将其放置在视图之外,然后将其动画化到视图中,这很好,但第一步检查它是否在这里):
此时您已经添加了视图中的横幅,因此即使未实现委托方法,它也应该出现。
一旦完成这项工作,您就可以详细说明管理动画的委托方法。
Basing my answser on Apple's code in ADBannerNavigation, you could strip it down to the essential to check the ad appears. I mean :
1) take the code as it is in the app delegate, defining an iAd and a SharedADBannerView, and in appdelegate.m :
2) the instance therefore exists when your controller comes into view, you could just add in viewDidAppear Apple's code but change the origin to something visible (Apple suggest to place it out of view and then animate it into view, which is fine but in a first step check it is here) :
At this point you've added the banner in view so it should appear even if the delegate methods are not implemented.
Once you make this work you can elaborate on the delegate methods to manage the animation.