观看奖励视频后重新加载 Table 视图
Reloading Table View After Watching a Rewarded Video
最近我在代码中实现了奖励视频功能,效果很好。简单地说,当用户从 table 视图中选择关卡并观看奖励视频时,它会解锁该关卡。但是当用户关闭广告视图时,table 视图保持不变,不会重新加载新信息。
我尝试了在这里找到的一些解决方案,但没有任何效果。
您可能需要使用 tableView.reloadData()
手动重新加载 table 视图。在 viewWillAppear 或广告播放完毕后触发的任何 notifications/callbacks 中执行此操作。
您可以简单地使用 NSNotification 来调用您的 tableView.reloadData():
添加
NotificationCenter.default.addObserver(self, selector: #selector(reload), name: NSNotification.Name(rawValue: "load"), object: nil)
你的 tableView 控制器 (TVC) ViewDidLoad
这个功能给你的 TVC
@objc func reload()
{
//setup ur new data
self.tableView.reloadData()
}
然后只需添加
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)
在你的 self.dismiss(animated: true, completion: nil)
在你的 RewardedVideo Player
之前
您可以在奖励视频开启控制器上设置事件通知。在 viewDidLoad
中使用这些代码行
GADRewardBasedVideoAd.sharedInstance().delegate = self
GADRewardBasedVideoAdDelegate notifies you of rewarded video lifecycle events. You are required to set the delegate prior to loading an ad. The most important event in this delegate is rewardBasedVideoAd:didRewardUserWithReward:, which is called when the user should be rewarded for watching a video. You may optionally implement other methods in this delegate.
那么你需要实现这个委托
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
didRewardUserWith reward: GADAdReward) {
print("Reward received with currency: \(reward.type), amount \(reward.amount).")
// RELOAD YOUR TABLE VIEW DATA HERE
}
详情可以看详细实现here
最近我在代码中实现了奖励视频功能,效果很好。简单地说,当用户从 table 视图中选择关卡并观看奖励视频时,它会解锁该关卡。但是当用户关闭广告视图时,table 视图保持不变,不会重新加载新信息。
我尝试了在这里找到的一些解决方案,但没有任何效果。
您可能需要使用 tableView.reloadData()
手动重新加载 table 视图。在 viewWillAppear 或广告播放完毕后触发的任何 notifications/callbacks 中执行此操作。
您可以简单地使用 NSNotification 来调用您的 tableView.reloadData(): 添加
NotificationCenter.default.addObserver(self, selector: #selector(reload), name: NSNotification.Name(rawValue: "load"), object: nil)
你的 tableView 控制器 (TVC) ViewDidLoad 这个功能给你的 TVC
@objc func reload()
{
//setup ur new data
self.tableView.reloadData()
}
然后只需添加
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)
在你的 self.dismiss(animated: true, completion: nil)
在你的 RewardedVideo Player
您可以在奖励视频开启控制器上设置事件通知。在 viewDidLoad
GADRewardBasedVideoAd.sharedInstance().delegate = self
GADRewardBasedVideoAdDelegate notifies you of rewarded video lifecycle events. You are required to set the delegate prior to loading an ad. The most important event in this delegate is rewardBasedVideoAd:didRewardUserWithReward:, which is called when the user should be rewarded for watching a video. You may optionally implement other methods in this delegate.
那么你需要实现这个委托
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
didRewardUserWith reward: GADAdReward) {
print("Reward received with currency: \(reward.type), amount \(reward.amount).")
// RELOAD YOUR TABLE VIEW DATA HERE
}
详情可以看详细实现here