Search code examples
iosswiftuisegmentedcontrol

how to set up the default view controller


I am trying to setup calculatorViewController as default when launching the app but instead of tah i get creatorViewController as the main view controller. however when tapped differents segmented and then tap back first tab calculatorViewController this is shown normal. How can i fix it???

@IBOutlet weak var segmentedControl: CustomSegmentedControl!

@IBOutlet weak var CalculatorViewController: UIView!
@IBOutlet weak var EvidenceViewController: UIView!
@IBOutlet weak var CreatorsViewController: UIView!

@IBAction func customSegmentValueChanged(_ sender: CustomSegmentedControl) {
    switch sender.selectedSegmentIndex {
        case 0:
            CalculatorViewController.isHidden = false
            EvidenceViewController.isHidden = true
            CreatorsViewController.isHidden = true
        case 1:
            CalculatorViewController.isHidden = true
            EvidenceViewController.isHidden = false
            CreatorsViewController.isHidden = true
        case 2:
            CalculatorViewController.isHidden = true
            EvidenceViewController.isHidden = true
            CreatorsViewController.isHidden = false
        default:
            CalculatorViewController.isHidden = true
    }
}

Solution

  • try this

         override func viewDidLoad() {
         super.viewDidLoad()
    
         segmentController.selectedSegmentIndex = 0
        //if you need to use tag then use this line otherwise skip it.
         segmentController.tag = segmentController.selectedSegmentIndex
        // only segmentController.tag line 
         self.segmentControllAction(segmentController)
    
        }
    

    and your outlet is ok dont change it