title: How do I call a fromRootViewController method within a UIView class?
body: <p>EDIT: This is a very beginner level question, so I apologise in advance</p>
  
  <p>This is a sub part of a homework assignment I'm trying to crack but seems kind of impossible. I have implemented GADRewardBasedVideoAdDelegate to my UIView for Rewarded ads on Google Admob, and managed to implement all other instances of this delegate within "PopUp", which is a subclass of UIView.</p>
  
  <p>However, this one method seems impossible to implement, which is:</p>
  
  <pre><code>    if GADRewardBasedVideoAd.sharedInstance().isReady == true {    
          GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
           }
  </code></pre>
  
  <p>where the issue is the ".present(fromRootViewController: self) portion of the code since the self refers not to a ViewController but to a UIView().</p>
  
  <p>I honestly don't know how to tackle this situation, so I do not have anything to show for my attempts at this issue. I would really be grateful for any guidance that I can get on this topic, I've been stuck here for the better part of 2 days.</p>
  
  <p>Here is the popUp class in case it helps make my code clearer</p>
  
  <pre><code>import UIKit
  import GoogleMobileAds
  
  class Popup: UIView, GADRewardBasedVideoAdDelegate {
  
      func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) {
          let vc = MainVC()
          vc.lifeNumber += 3
          vc.numberOfLivesLabel.text = "\(vc.lifeNumber)"
      }
  
      func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
          GADRewardBasedVideoAd.sharedInstance().load(GADRequest(), withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
      }
  
  
      let playButton: UIButton = {
          let button = UIButton()
          button.translatesAutoresizingMaskIntoConstraints = false
          button.setImage(UIImage(named: "icon"), for: .normal)
          button.addTarget(self, action: #selector(play), for: .touchUpInside)
          return button
      }()
  
      @objc func play() {
          print("Play button pressed.")
          if GADRewardBasedVideoAd.sharedInstance().isReady == true {
              GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self) //&lt;---------ERRONEOUS CODE
               }
      }
  
  
      override init(frame: CGRect) {
          super.init(frame: frame)
  
          GADRewardBasedVideoAd.sharedInstance().load(GADRequest(), withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
          GADRewardBasedVideoAd.sharedInstance().delegate = self
  
  
  self.addSubview(popUpContainer)
  playButton.centerXAnchor.constraint(equalTo: popUpContainer.centerXAnchor),
      playButton.topAnchor.constraint(equalTo: popUpContainer.topAnchor, constant: 15),
      playButton.heightAnchor.constraint(equalToConstant: 300)
      playButton.widthAnchor.constraint(equalToConstant: 300)
      }
  
      required init?(coder aDecoder: NSCoder) {
          fatalError("Could not run init(coder)")
      }
  }
  </code></pre>
  
  <p>And here is my MainVC()</p>
  
  <pre><code>class MainVC: UIViewController {
  
      var lifeNumber: Int = 3
  
      lazy var numberOfLivesLabel: UILabel = {
          let label = UILabel()
          label.text = "\(lifeNumber)"
          label.font = UIFont(name: "Copperplate", size: 25)
          label.translatesAutoresizingMaskIntoConstraints = false
          return label
      }()
  
      let buttonOne: UIButton = {
          let button = UIButton(type: .system)
          button.setTitle("Hit me!", for: .normal)
          button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
          button.translatesAutoresizingMaskIntoConstraints = false
          return button
      }()
  
      @objc func buttonPressed() {
          let popUpView = Popup()
          self.view.addSubview(popUpView)
      }
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          view.backgroundColor = .systemBlue
  
          view.addSubview(buttonOne)
          view.addSubview(numberOfLivesLabel)
  
          buttonOne.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
          buttonOne.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
          buttonOne.heightAnchor.constraint(equalToConstant: 300).isActive = true
          buttonOne.widthAnchor.constraint(equalToConstant: 300).isActive = true
  
          numberOfLivesLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
          numberOfLivesLabel.bottomAnchor.constraint(equalTo: buttonOne.topAnchor, constant: 50).isActive = true
  
      }
  }
  </code></pre>