title: Segue background flicker upon first load in Swift
body: <p>I am getting a flicker (likely view controller not fully loaded) for a split second upon first load on my second view controller.  I've tried to preset through a segue as well as setting it in a custom initializer prior to load.  The affect that I've created is to keep the same background for each view controller.  Note, that this only occurs upon first transition over to the view controller.  It doesn't happen after the first segue.</p>
  
  <p>Help is greatly appreciated.  I'm including the applicable code below.</p>
  
  <p><strong>First View Controller:</strong></p>
  
  <pre><code> class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate, UIScrollViewDelegate
  {
  // Background Image
  var backgroundImage: UIImageView!
  var backgroundImages: [String] = ["canyon.jpeg","channel.jpeg","glacier.jpeg","northernlights.jpeg", "jungle"]
  var currentBackground = 0
  
  init(_ coder: NSCoder? = nil)
  {
      // Logic Goes Here
  
      if let coder = coder
      {
          super.init(coder: coder)!
      } else
      {
          super.init(nibName: nil, bundle: nil)
      }
  }
  
  required convenience init(coder: NSCoder)
  {
      self.init(coder)
  }
  
  override func viewDidLoad()
  {
      setUpView()
      super.viewDidLoad()
  }
  
  func setUpView()
  {
      backgroundImage = UIImageView(frame: CGRect( x: 0 , y: 0, width: ScreenWidth, height: ScreenHeight))
      backgroundImage.image = UIImage(named: backgroundImages[currentBackground])
      backgroundImage.alpha = 1
  
      let playButtonPercent:CGFloat = 0.75
      playButton = UIButton(frame: CGRect(x: (ScreenWidth * 0.5) - (ScreenWidth * playButtonPercent / 2), y: (ScreenHeight * (3 / 4)) - (ScreenHeight * (15/480)), width: (ScreenWidth * playButtonPercent), height: ScreenHeight * (30/480)))
      playButton.setTitle("PLAY", for: UIControlState())
      playButton.addTarget(self, action: #selector(self.playRelease), for: .touchUpInside)
  
      self.view.addSubview(backgroundImage)
      self.view.addSubview(playButton)
  }
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?)
  {
      if (segue.identifier == "Play")
      {
          if let nextViewController = (segue.destination as? GameListViewController)
          {
              nextViewController.currentBackground = currentBackground
              nextViewController.backgroundImage.image = UIImage(named: self.backgroundImages[currentBackground])
          }
      }
  }
  
  func playRelease()
  {        
      // Segue
      performSegue(withIdentifier: "Play", sender: self)
  }
  }
  </code></pre>
  
  <p><strong>View Controller 2:</strong></p>
  
  <pre><code> class GameListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
   {
  let backgroundImages = ["canyon.jpeg","channel.jpeg","glacier.jpeg","northernlights.jpeg", "jungle"]
  var currentBackground = 0
  var backgroundImage: UIImageView!
  
  override func viewDidLoad()
  {
      backgroundImage = UIImageView(frame: CGRect( x: 0 , y: 0, width: ScreenWidth, height: ScreenHeight))
      super.viewDidLoad()
      setUpView()
      }
  }
  
  func setUpView()
  {
      backgroundImage.image = UIImage(named: backgroundImages[currentBackground])
      backgroundImage.alpha = 1
  
      self.view.addSubview(backgroundImage)
      view.sendSubview(toBack: backgroundImage)
  }
  }
  </code></pre>