Swift: cannot convert value of type 'GameScene' to expected argument type 'UIViewController!'

风流意气都作罢 提交于 2020-01-07 03:29:11

问题


I am trying to load an admob interstitial ad in my app when the users lost but i can't because i am using spritekit (swift), here's my code:

 self.interstitial.presentFromRootViewController(interstitial)

and here's my error:

cannot convert value of type 'GameScene' to expected argument type 'UIViewController!'

Hope one of you has the answer! thx


回答1:


You're trying to present interstitial from itself.

You should present it from a ViewController which is currently visible:

self.interstitial.presentFromRootViewController(self)

(supposed that self is a View Controller).

Update:

If you follow Google tutorial attentively, you will see there exactly what I'm talking about:

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


来源:https://stackoverflow.com/questions/34692755/swift-cannot-convert-value-of-type-gamescene-to-expected-argument-type-uivie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!