title: Segmented Control not working as expected on Segment 0
body: <p>I have a segmented control that alters 5 images on one of my View Controllers (see image below) but I want Segment 0 to be selected straight away when someone goes into the Casting Tab. At present it only gets selected when i go onto either Segment 1 or 2 and then back, after that it obviously works as it should.</p>
  
  <p>In the Attributes Inspector beside Behavior I have Enabled and Selected ticked, I have even tried State Selected ticked but always the same result so I'm unsure where I'm going wrong. I can get a visual fix by adding code to my ViewDidLoad for the 5 images, setting four of them to .isHidden = true and one to .isHidden = false but this doesn't solve my problem obviously.</p>
  
  <p>Here is my code:    </p>
  
  <pre><code>    import UIKit
  
          class CastingViewController: UIViewController {
  
              let runesArray = [Rune(runeName: "Fehu", runeImage: UIImage(named: ("Fehu.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Uruz", runeImage: UIImage(named: ("Uruz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Thurisaz", runeImage: UIImage(named: ("Thurisaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Ansuz", runeImage: UIImage(named: ("Ansuz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Raidho", runeImage: UIImage(named: ("Raidho.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Kenaz", runeImage: UIImage(named: ("Kenaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Gebo", runeImage: UIImage(named: ("Gebo.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Wunjo", runeImage: UIImage(named: ("Wunjo.png"))!, runeDescription: "Description goes here."),
  
                                Rune(runeName: "Hagalaz", runeImage: UIImage(named: ("Hagalaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Nauthiz", runeImage: UIImage(named: ("Nauthiz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Isa", runeImage: UIImage(named: ("Isa.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Jera", runeImage: UIImage(named: ("Jera.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Eihwaz", runeImage: UIImage(named: ("Eihwaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Perthro", runeImage: UIImage(named: ("Perthro.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Algiz", runeImage: UIImage(named: ("Algiz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Sowilo", runeImage: UIImage(named: ("Sowilo.png"))!, runeDescription: "Description goes here."),
  
                                Rune(runeName: "Tiwaz", runeImage: UIImage(named: ("Tiwaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Berkano", runeImage: UIImage(named: ("Berkano.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Ehwaz", runeImage: UIImage(named: ("Ehwaz.png"))!, runeDescription: "(Description goes here."),
                                Rune(runeName: "Mannaz", runeImage: UIImage(named: ("Mannaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Laguz", runeImage: UIImage(named: ("Laguz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Ingwaz", runeImage: UIImage(named: ("Ingwaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Dagaz", runeImage: UIImage(named: ("Dagaz.png"))!, runeDescription: "Description goes here."),
                                Rune(runeName: "Othala", runeImage: UIImage(named: ("Othala.png"))!, runeDescription: "Description goes here.")]
  
              var runesCastArray: [UIImage] = [] // Array to save Rune images for 3 or 5 Rune Cast
  
      @IBOutlet weak var segmentedControl: UISegmentedControl!
      @IBOutlet weak var runeOne: UIImageView!
      @IBOutlet weak var runeTwo: UIImageView!
      @IBOutlet weak var runeThree: UIImageView!
      @IBOutlet weak var runeFour: UIImageView!
      @IBOutlet weak var runeFive: UIImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
  
      }
  
      override func viewWillAppear(_ animated: Bool) {
          segmentedControl.selectedSegmentIndex = 0
      }
  
      var runeCast = 0 // Need to check if this will work in a Switch statement
  
      var storedRuneOne: UIImage!
      var storedRuneTwo: UIImage!
      var storedRuneThree: UIImage!
      var storedRuneFour: UIImage!
      var storedRuneFive: UIImage!
  
      func oneRuneCast() {
  
          runeCast = 1
          runeOne.isHidden = true
          runeTwo.isHidden = true
          runeThree.isHidden = true
          runeFour.isHidden = true
          runeFive.isHidden = false
  
      }
  
      func threeRuneCast() {
  
          runeCast = 3
          runeOne.isHidden = true
          runeTwo.isHidden = false
          runeThree.isHidden = true
          runeFour.isHidden = false
          runeFive.isHidden = false
  
      }
  
      func fiveRuneCast() {
  
          runeCast = 5
          runeOne.isHidden = false
          runeTwo.isHidden = false
          runeThree.isHidden = false
          runeFour.isHidden = false
          runeFive.isHidden = false
  
      }
  
      @IBAction func castType(_ sender: Any) {
  
         switch segmentedControl.selectedSegmentIndex {
          case 0:
              oneRuneCast()
          case 1:
              threeRuneCast()
          case 2:
              fiveRuneCast()
          default: break
          }
  
      }
  
      @IBAction func castButtonPressed(_ sender: Any) {
  
          if runeCast == 1 {
  
          let randomRunes = runesArray[Int(arc4random_uniform(UInt32(runesArray.count)))]
  
              runeFive.image = randomRunes.runeImage
  
  
          } else if runeCast == 3 {
  
              let randomRunes = runesArray[Int(arc4random_uniform(UInt32(runesArray.count)))]
  
              runeTwo.image = randomRunes.runeImage
              runeFour.image = randomRunes.runeImage
              runeFive.image = randomRunes.runeImage
  
          } else if runeCast == 5 {
  
              let randomRunes = runesArray[Int(arc4random_uniform(UInt32(runesArray.count)))]
  
              runeOne.image = randomRunes.runeImage
              runeTwo.image = randomRunes.runeImage
              runeThree.image = randomRunes.runeImage
              runeFour.image = randomRunes.runeImage
              runeFive.image = randomRunes.runeImage
  
              }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cxvXS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cxvXS.png" alt="enter image description here"></a></p>