Home>
  

As shown in the image below, secondViewController and SecondSwitchViewController are connected with Present Modally, and when the button is tapped, the screen transitions.
  However, if you tap the Tab Bar Controller's History, it will directly connect to the SecondSwitchViewController. After that, if you tap Back and return to SeconViewController, it will move ideally unless you tap the Button part. Why is it forced to switch only at the beginning? I would be happy if you could tell me. Thank you.

  

Attach the SecondViewController code

import UIKit
import AVFoundation
class SecondViewController: UIViewController, AVAudioPlayerDelegate, UITableViewDelegate, UITableViewDataSource, GADBannerViewDelegate {
    let TODO = ["a", "b", "c", "d", "e", "f"]
    var counter = 0
    var timer = Timer ()
    var startTime: Double = 0.0
    var audioPlayer: AVAudioPlayer!
    @IBOutlet weak var tableView: UITableView!
    @IBAction func switch1 (_ sender: UISwitch)
    {
        if (sender) .isOn
        {
            timer = Timer.scheduledTimer (withTimeInterval: 1 * 1, repeats: false, block: {timer in
                self.audioPlayer.play ()
                self.audioPlayer.numberOfLoops = -1
                print (self.audioPlayer.isPlaying)
            })
        } else {
            timer.invalidate ()
            print ("switch1stopped")
            self.audioPlayer.stop ()
        }
    }
    @IBAction func switch1setting (_ sender: UIButton)
    {
        counter = counter + 1
        print (counter)
        if counter == 2 {
            self.performSegue (withIdentifier: "nextView", sender: nil)
            counter = 0
        }
        // First we define here that it is in the same storyboard
        let storyboard: UIStoryboard = self.storyboard!
        // Select the destination storyboard here (in this case, I named it earlier because I named it second)
        let second = storyboard.instantiateViewController (withIdentifier: "nextView")
        // This is the code that actually moves
        self.present (second, animated: true, completion: nil)
    }
    @IBAction func switch2 (_ sender: UISwitch)
    {
        if (sender) .isOn
        {
            timer = Timer.scheduledTimer (withTimeInterval: 1 * 1, repeats: false, block: {timer in
                self.audioPlayer.play ()
                self.audioPlayer.numberOfLoops = -1
                print (self.audioPlayer.isPlaying)
            })
        } else {
            timer.invalidate ()
            print ("switch2stopped")
            self.audioPlayer.stop ()
        }
    }
    @IBAction func switch2setting (_ sender: UIButton)
    {
        counter = counter + 1
        print (counter)
        if counter == 2 {
            self.performSegue (withIdentifier: "secondsetting", sender: nil)
            counter = 0
        }
        // First we define here that it is in the same storyboard
        let storyboard: UIStoryboard = self.storyboard!
        // Select the destination storyboard here (in this case, I named it earlier because I named it second)
        let second = storyboard.instantiateViewController (withIdentifier: "secondsetting")
        // This is the code that actually moves
        self.present (second, animated: true, completion: nil)
    }

    override func viewDidLoad () {
        super.viewDidLoad ()
    }