Swift:无法转换类型' GameScene'预期的参数类型' UIViewController!'

时间:2016-01-09 11:13:05

标签: swift admob interstitial

我想在用户丢失时在我的应用中加载一个admob插页式广告,但我不能因为我使用的是spritekit(swift),这是我的代码:

 self.interstitial.presentFromRootViewController(interstitial)

这是我的错误:

cannot convert value of type 'GameScene' to expected argument type 'UIViewController!'
希望你们中的一个人有答案! thx

1 个答案:

答案 0 :(得分:0)

您试图自己展示interstitial

您应该从当前可见的ViewController中显示它:

self.interstitial.presentFromRootViewController(self)

(假设self是一个视图控制器)。

<强>更新

如果您密切关注Google tutorial ,您会看到我正在谈论的内容:

func gameOver() {
  if self.interstitial.isReady {
    self.interstitial.presentFromRootViewController(self)
  }
  // Rest of game over logic goes here.
}