ios:how 要在 swift 中的导航项的后退按钮上添加 google 广告?
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.
should would be come and when i close ads. first view controller
should open.
谢谢
创建后退按钮时,您应该为该后退按钮定义 selector/action 方法。
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{
}
}
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. should would be come and when i close ads. first view controller should open.
谢谢
创建后退按钮时,您应该为该后退按钮定义 selector/action 方法。
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{
}
}