首页 \ 问答 \ 使用UITableViews在app上使用ADBannerView的共享实例(using shared instance of ADBannerView across app with UITableViews)

使用UITableViews在app上使用ADBannerView的共享实例(using shared instance of ADBannerView across app with UITableViews)

我有一个带有多个UITableViews的应用程序,我正在实现iADs。 根据Apple文档( http://developer.apple.com/library/ios/#technotes/tn2286/_index.html#//apple_ref/doc/uid/DTS40011212 )我创建了一个属于我的app delegate的共享横幅并且应用程序委托也是横幅的委托。 这很有效,广告在加载横幅和用户切换屏幕后很好地显示在各种视图控制器上。

问题是在第一个viewController上没有看到广告,因为视图控制器的viweWillAppear方法(我称之为“fixUpAdView”方法)在加载横幅之前出现。

我想我得到的部分是这个(来自苹果文档):“让你的应用程序代理告诉当前的视图控制器它是否应该显示或隐藏横幅。你可以使用UINavigationControllerDelegate或UITabBarControllerDelegate协议推送横幅来显示它。” 我知道我需要在bannerViewDidLoadAd和failToReceive方法中添加一些内容,但是对于如何执行此操作我感到有点困惑。

我不希望广告在我的所有视图控制器上显示(只有其中的6个),并且我在应用程序中也有多个模态视图(其中任何一个都没有广告)。

以下是我的一些代码:在我的appDelegate中:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewDidLoadAD");
    if (!_adBannerViewIsVisible) 
        _adBannerViewIsVisible = YES;

}


- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{

    NSLog(@"BannerAd didfailtoreceive");
    if (_adBannerViewIsVisible)
        _adBannerViewIsVisible = NO;

}

- (ADBannerView *)sharedAdBannerView 
{
    if (_sharedAdBannerView == nil) {

        Class classAdBannerView = NSClassFromString(@"ADBannerView");

        if (classAdBannerView != nil) {
            _sharedAdBannerView = [[classAdBannerView alloc] initWithFrame:CGRectZero];
            [_sharedAdBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects: 
                                                              ADBannerContentSizeIdentifier320x50, 
                                                              ADBannerContentSizeIdentifier480x32, nil]];
            [_sharedAdBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];            
            [_sharedAdBannerView setFrame:CGRectOffset([_sharedAdBannerView frame], 0, 
                                                 -(iAD_BANNER_HEIGHT))];
            [_sharedAdBannerView setDelegate:self];
        }
    }

    return _sharedAdBannerView;
}

在我的视图控制器中:

- (void)viewWillAppear:(BOOL)animated {

    if ([[AppDelegate ad] shouldShowAds]) {

        if (!self.contentView) {
            self.contentView = [[UIView alloc] initWithFrame:[[self view] bounds]];
            [self.view addSubview:_contentView];
        }
        [self.contentView addSubview:topView];
        [self fixupAdView];
        [self.view addSubview:[[AppDelegate ad] sharedAdBannerView]];
    }
    [super viewWillAppear:NO];
}


#pragma mark
#pragma mark iADS

- (void)fixupAdView {

    if ([[AppDelegate ad] sharedAdBannerView] != nil) {        

        [[[AppDelegate ad] sharedAdBannerView] setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];
        [UIView beginAnimations:@"fixupViews" context:nil];

        if ([[AppDelegate ad] adBannerViewIsVisible]) {
            CGRect adBannerViewFrame = [[[AppDelegate ad] sharedAdBannerView] frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = 0;
            [[[AppDelegate ad] sharedAdBannerView] setFrame:adBannerViewFrame];
            CGRect contentViewFrame = _contentView.frame;
            contentViewFrame.origin.y = iAD_BANNER_HEIGHT;
            contentViewFrame.size.height = self.view.frame.size.height - 
            iAD_BANNER_HEIGHT;
            _contentView.frame = contentViewFrame;
        } 
        else {
            CGRect adBannerViewFrame = [[[AppDelegate ad] sharedAdBannerView] frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = -(iAD_BANNER_HEIGHT);
            [[[AppDelegate ad] sharedAdBannerView] setFrame:adBannerViewFrame];
            CGRect contentViewFrame = _contentView.frame;
            contentViewFrame.origin.y = 0;
            contentViewFrame.size.height = self.view.frame.size.height;
            _contentView.frame = contentViewFrame;            
        }
        [UIView commitAnimations];
    }   
}

I have an app with multiple UITableViews and am in the process of implementing iADs. Per the Apple documentation (http://developer.apple.com/library/ios/#technotes/tn2286/_index.html#//apple_ref/doc/uid/DTS40011212) I have created a shared banner that belongs to my app delegate and the application delegate is also the banner's delegate. This works well and the ads show nicely across the various view controllers AFTER the banner is loaded and the user switches screens.

The problem is that there is no ad seen on the first viewController that comes up because the viweWillAppear method of the view controller (where I am calling my "fixUpAdView" method) comes before the banner is loaded.

I guess the part that I am not getting is this (from the apple documentation): "Have your application delegate tell the current view controller if it should show or hide the banner. You can use UINavigationControllerDelegate or UITabBarControllerDelegate protocol to push the banner to show it." I understand that I need to be putting something into my bannerViewDidLoadAd and failToReceive methods but am a bit confused as to how to do this.

I do not want the ad to show on all of my view controllers (just 6 of them) and I also have several modal views in the app (no ad on any of these).

Here is some of my code: In my appDelegate:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewDidLoadAD");
    if (!_adBannerViewIsVisible) 
        _adBannerViewIsVisible = YES;

}


- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{

    NSLog(@"BannerAd didfailtoreceive");
    if (_adBannerViewIsVisible)
        _adBannerViewIsVisible = NO;

}

- (ADBannerView *)sharedAdBannerView 
{
    if (_sharedAdBannerView == nil) {

        Class classAdBannerView = NSClassFromString(@"ADBannerView");

        if (classAdBannerView != nil) {
            _sharedAdBannerView = [[classAdBannerView alloc] initWithFrame:CGRectZero];
            [_sharedAdBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects: 
                                                              ADBannerContentSizeIdentifier320x50, 
                                                              ADBannerContentSizeIdentifier480x32, nil]];
            [_sharedAdBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];            
            [_sharedAdBannerView setFrame:CGRectOffset([_sharedAdBannerView frame], 0, 
                                                 -(iAD_BANNER_HEIGHT))];
            [_sharedAdBannerView setDelegate:self];
        }
    }

    return _sharedAdBannerView;
}

In my view controller:

- (void)viewWillAppear:(BOOL)animated {

    if ([[AppDelegate ad] shouldShowAds]) {

        if (!self.contentView) {
            self.contentView = [[UIView alloc] initWithFrame:[[self view] bounds]];
            [self.view addSubview:_contentView];
        }
        [self.contentView addSubview:topView];
        [self fixupAdView];
        [self.view addSubview:[[AppDelegate ad] sharedAdBannerView]];
    }
    [super viewWillAppear:NO];
}


#pragma mark
#pragma mark iADS

- (void)fixupAdView {

    if ([[AppDelegate ad] sharedAdBannerView] != nil) {        

        [[[AppDelegate ad] sharedAdBannerView] setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];
        [UIView beginAnimations:@"fixupViews" context:nil];

        if ([[AppDelegate ad] adBannerViewIsVisible]) {
            CGRect adBannerViewFrame = [[[AppDelegate ad] sharedAdBannerView] frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = 0;
            [[[AppDelegate ad] sharedAdBannerView] setFrame:adBannerViewFrame];
            CGRect contentViewFrame = _contentView.frame;
            contentViewFrame.origin.y = iAD_BANNER_HEIGHT;
            contentViewFrame.size.height = self.view.frame.size.height - 
            iAD_BANNER_HEIGHT;
            _contentView.frame = contentViewFrame;
        } 
        else {
            CGRect adBannerViewFrame = [[[AppDelegate ad] sharedAdBannerView] frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = -(iAD_BANNER_HEIGHT);
            [[[AppDelegate ad] sharedAdBannerView] setFrame:adBannerViewFrame];
            CGRect contentViewFrame = _contentView.frame;
            contentViewFrame.origin.y = 0;
            contentViewFrame.size.height = self.view.frame.size.height;
            _contentView.frame = contentViewFrame;            
        }
        [UIView commitAnimations];
    }   
}

原文:https://stackoverflow.com/questions/10433565
更新时间:2022-03-30 14:03

最满意答案

在您的情况下,像这样的MERGE语句应该有效。 请注意,我从DUAL表中选择一条记录。 您可以使用DUAL多个UNION ALL进行多行操作。

MERGE INTO yourtable target
     USING (SELECT 1 AS id, 'value_1' AS column_1, 'value_2' AS column_2
              FROM DUAL) source
        ON (source.id = target.id)
WHEN MATCHED
THEN
   UPDATE SET
      target.column_1 = source.column_1, target.column_2 = source.column_2
WHEN NOT MATCHED
THEN
   INSERT     (column_1, column_2)
       VALUES (source.column_1, source.column_2);

In your case, a MERGE statement like this should work. Note that I am selecting a single record from DUAL table. you may use multiple UNION ALLs from DUAL for multiple rows.

MERGE INTO yourtable target
     USING (SELECT 1 AS id, 'value_1' AS column_1, 'value_2' AS column_2
              FROM DUAL) source
        ON (source.id = target.id)
WHEN MATCHED
THEN
   UPDATE SET
      target.column_1 = source.column_1, target.column_2 = source.column_2
WHEN NOT MATCHED
THEN
   INSERT     (column_1, column_2)
       VALUES (source.column_1, source.column_2);

相关问答

更多
  • merge into 时,如果b表(辅助表)中有重复记录,在matched条件下, update时就会出错。因为数据库不知道用哪一条匹配的结果。
  • oracle merge的使用[2022-09-26]

    Oracle9i引入了MERGE命令,你能够在一个SQL语句中对一个表同时执行inserts和updates操作. MERGE命令从一个或多个数据源中选择行来updating或inserting到一个或多个表.在Oracle10g中MERGE有如下一些改进: 1、UPDATE或INSERT子句是可选的 2、UPDATE和INSERT子句可以加WHERE子句 3、在ON条件中使用常量过滤谓词来insert所有的行到目标表中,不需要连接源表和目标表 4、UPDATE子句后面可以跟DELETE子句来去除一些不需要 ...
  • 在您的情况下,像这样的MERGE语句应该有效。 请注意,我从DUAL表中选择一条记录。 您可以使用DUAL多个UNION ALL进行多行操作。 MERGE INTO yourtable target USING (SELECT 1 AS id, 'value_1' AS column_1, 'value_2' AS column_2 FROM DUAL) source ON (source.id = target.id) WHEN MATCHED THE ...
  • 使用TABLE()运算符,您可以使用SQL语句操作集合,就像它们是DB表一样。 例如,在你的情况下,执行一个FULL OUTER JOIN : SELECT obj_test(id,NVL(T1.val,0)+NVL(T2.val,0)) BULK COLLECT INTO list3 FROM TABLE(list1) T1 FULL OUTER JOIN TABLE(list2) T2 USING(id); 鉴于你的两个样本列表,这将存储在list3中: 1 400 2 2 ...
  • 如果您使用10g,您也可以使用插入条件: http://www.oracle-developer.net/display.php?id=310 RGDS。 If you're using 10g, you may use conditions for the insert as well: http://www.oracle-developer.net/display.php?id=310 Rgds.
  • 多个会话将执行此操作,也就是说,如果您没有适当的约束条件。 例 Session 1 SQL> create table t ( x int ); Table created. SQL> SQL> declare 2 incoming_value int := 1; 3 begin 4 MERGE INTO t USING dual ON (x = incoming_value ) 5 WHEN NOT MATCHED THEN INSERT (x) 6 ...
  • insert很可能更快,因为它不需要在两个表上进行连接。 也就是说,这两个查询并不等同。 假设col1被定义为主键,如果data_source包含col1中已存在于data_dest中的值,则insert将引发错误。 因为merge是比较两个表中的数据,然后只插入尚不存在的行,所以它不会抛出主键冲突。 一个等同于merge的insert将是: INSERT INTO data_dest SELECT data_source.col1, data_source.col2, ... data_source ...
  • 可能解决您的问题的一种方法是将insert语句从值转换为select。 尝试这个 - INSERT INTO FACT_ATTRIBUTE ( KEY, VALUE ) SELECT max(key) over (partition by value) + 1 as key_max, f.entry FROM ( SELECT f.entry, fa.value FROM fact_table f LEFT ...
  • MERGE对目标表上的操作很有用,而不是源。 您可以使用匿名PLSQL块: begin delete from my_data_backup; insert into my_data_backup select * from my_data; delete from my_data; commit; exception when others then rollback; -- handle here end; / 您 ...
  • 以下MERGE查询是您正在寻找的。 MERGE INTO myTable tgt USING ( select x.rid from (SELECT myTable.ROWID AS rid FROM myTable WHERE myTable.myRef IN ('myref1','uuuu')) x right outer join dual on x.rowid <> dual.rowid ) src ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)