繁体   English   中英

ios:如何在swift导航项的后退按钮上添加谷歌广告?

[英]ios:how to add google ads on back button of navigation item in swift?

 let backButton = UIBarButtonItem(
        title: "",
        style: UIBarButtonItemStyle.Plain,
        target: nil,
        action: nil
    );
    self.navigationController!.navigationBar.tintColor = UIColor.whiteColor()
    self.navigationController!.navigationBar.topItem!.backBarButtonItem = backButton;

我使用上面的代码,我想在导航项的后退按钮中添加谷歌非页内广告。 我的要求是当我从第二个viewcontroller广告回来时。 应该来,当我关闭广告。 第一个视图控制器应该打开

谢谢

在创建后退按钮时,您应该为该后退按钮定义选择器/操作方法。

let backButton = UIBarButtonItem(
    title: "",
    style: UIBarButtonItemStyle.Plain,
    target: self,
    action: #selector(backButtonPressed)
)

在同一个控制器中,您可以使用单击后退按钮后执行的方法

func backButtonPressed(){
   Print("Back Button Pressed")

   //Write code for showing google ads here.

}

我通过在secondViewController中添加以下代码解决了我的问题。 和它的工作完美。

 override func viewWillDisappear(animated: Bool) {
    if (interstitial.isReady && showAd) {
        showAd = false
        print("iterstitalMain is ready")
        interstitial.presentFromRootViewController(parentViewController!)
        self.createAndLoadInterstitial()
    }
    else{
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM