Ios 从IAP从UIViewController中删除AdBannerView而无需重新启动应用程序

Ios 从IAP从UIViewController中删除AdBannerView而无需重新启动应用程序,ios,objective-c,iphone,nsnotification,adbannerview,Ios,Objective C,Iphone,Nsnotification,Adbannerview,我有一个5个选项卡UITabBarController,其中每个选项卡都是一个UIViewController。第一个选项卡称为时间线,第二个选项卡称为人员,最后一个选项卡称为更多 我已经在我的应用程序中实施了应用程序内购买s,在IAP之前,用户不能更改主题等。我在这个版本中要做的一件事是使用IAP删除iad 因此,在制作IAP之前,Timeline的底部有一个AdBannerView,当IAP从More选项卡购买后,我希望AdBannerView会立即从Timeline中删除 问题 现在实际发

我有一个5个选项卡
UITabBarController
,其中每个选项卡都是一个
UIViewController
。第一个选项卡称为
时间线
,第二个选项卡称为
人员
,最后一个选项卡称为
更多

我已经在我的应用程序中实施了
应用程序内购买
s,在
IAP
之前,用户不能更改主题等。我在这个版本中要做的一件事是使用
IAP
删除
iad

因此,在制作
IAP
之前,
Timeline
的底部有一个
AdBannerView
,当
IAP
More
选项卡购买后,我希望
AdBannerView
会立即从
Timeline
中删除

问题

现在实际发生的事情是,我转到
更多
选项卡,购买
IAP
并返回
时间线
,而
AdBannerView
仍然存在。如果我从
时间线
选项卡移动到
人员
选项卡并返回到
时间线
选项卡,则
AdBannerView
将被删除。或者,如果我在
IAP
之后重新启动应用程序,则
AdBannerView
将从
时间线中删除。无论哪种方式,它都没有达到我预期的效果,即在我第一次从
More
选项卡返回
IAP
之后的
Timeline
选项卡时,删除
AdBannerView

下面是一些代码:

- (void)displayiAdsOrNot
{
    NSLog(@"Display iAds or Not");
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"IAPSuccessful"])
    {
        NSLog(@"BASIC");

        self.adBanner = [[self appdelegate] adBanners];
        self.adBanner.delegate = self;

        if (IDIOM == IPAD)
        {
            NSLog(@"*** This is the iPad ***");
            [self.adBanner setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, 320, 50)];
            [self.adBanner setTranslatesAutoresizingMaskIntoConstraints:NO];

            [self.view addSubview:self.adBanner];
            NSLayoutConstraint *myConstraint =[NSLayoutConstraint
                                               constraintWithItem:self.adBanner
                                               attribute:NSLayoutAttributeLeading
                                               relatedBy:NSLayoutRelationEqual
                                               toItem:self.view
                                               attribute:NSLayoutAttributeLeading
                                               multiplier:1.0
                                               constant:0];

            [self.view addConstraint:myConstraint];



            myConstraint =[NSLayoutConstraint constraintWithItem:self.adBanner
                                                       attribute:NSLayoutAttributeTrailing
                                                       relatedBy:NSLayoutRelationEqual
                                                          toItem:self.view
                                                       attribute:NSLayoutAttributeTrailing
                                                      multiplier:1
                                                        constant:0];

            [self.view addConstraint:myConstraint];

            myConstraint =[NSLayoutConstraint constraintWithItem:self.adBanner
                                                       attribute:NSLayoutAttributeBottom
                                                       relatedBy:NSLayoutRelationEqual
                                                          toItem:self.view
                                                       attribute:NSLayoutAttributeBottom
                                                      multiplier:1
                                                        constant:0];

            [self.view addConstraint:myConstraint];

        }
        else
        {
            NSLog(@"*** THIS IS THE IPHONE ***");
            [self.adBanner setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-98, 320, 50)];
            [self.view addSubview:self.adBanner];
        }

    }
    else
    {
        NSLog(@"PRO");
        [self.adBanner removeFromSuperview];
        self.adBanner = nil;
    }   
}
此方法仅从
视图调用,将出现

NSLogs
为指南,在
时间线
选项卡中,控制台显示
BASIC
。当我转到
More
选项卡,购买
IAP
并返回到
Timeline
选项卡时,
视图将再次出现,该视图将触发
displayiAdsOrNot
方法,这一次,我得到了
NSLog
PRO
,因为
NSUserDefault
iapsusccessful
现在是真的(这是在购买过程中完成的)

但是,此时仍会显示
AdBannerView

我尝试过的

我已经尝试了很多方法来让它工作:

  • 当购买完成时,创建一个
    NSNotification
    ,在
    视图中将出现
    时间线
    选项卡的方法。在该方法中,将
    self.adBanner
    设置为
    nil
    ,将其从superview中删除,等等。选择器将被
    通知触发(在
    视图出现之前),但不会发生任何变化
    
  • 我尝试了self.adBanner.delegate=self;self.adBanner=nil;[self.adBanner从SuperView中移除]等,它是相同的
  • 我尝试了
    [self.timelineTableView reloadData]
  • 在这个类似的SO问题()之后,我甚至尝试将ivar设置为无效
  • 我试着将
    self.adBanner
    放在屏幕外,但同样的事情正在发生;加载时间轴时,
    AdBannerView
    仍在那里,直到我转到其他地方
我的
视图将消失
,如下所示:

- (void)viewWillDisappear:(BOOL)animated
{
    self.adBanner.delegate = nil;
    self.adBanner=nil;
    [self.adBanner removeFromSuperview];
}
这是为了使用共享的
AdBannerViews
self.adBanner
是在.h文件中创建的属性,我正在.m文件中使用
@synthesis-adBanner=\u-adBanner


如果您对此有任何指导,我们将不胜感激

我已经解决了这个问题

通过删除
视图将消失
并设置
self.adBanner.hidden
=YES
如果
成功
,并在
通知中
,我成功地摆脱了
AdBannerView
,而无需重新启动应用程序