[英]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;
i have use above code and i want to add google Interstitial ads in back button of navigation item. 我使用上面的代码,我想在导航项的后退按钮中添加谷歌非页内广告。 my requirement is when i press back from second viewcontroller ads. 我的要求是当我从第二个viewcontroller广告回来时。 should would be come and when i close ads. 应该来,当我关闭广告。 first view controller should open. 第一个视图控制器应该打开
thanks 谢谢
While creating back button, you should define selector/action methods for that backbutton. 在创建后退按钮时,您应该为该后退按钮定义选择器/操作方法。
let backButton = UIBarButtonItem(
title: "",
style: UIBarButtonItemStyle.Plain,
target: self,
action: #selector(backButtonPressed)
)
in same controller you can have method which will execute after clicking back button 在同一个控制器中,您可以使用单击后退按钮后执行的方法
func backButtonPressed(){
Print("Back Button Pressed")
//Write code for showing google ads here.
}
i solved my problem by adding this below code in secondViewController. 我通过在secondViewController中添加以下代码解决了我的问题。 and its work perfectly. 和它的工作完美。
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.