简体   繁体   中英

xcode swift4 how do I change the page in viewdidload

I cannot use segue on viewDidLoad.

I already check the segue is worded on another func.

When load the view check some condition then change view this is what I want.

override func viewDidLoad(){
  super.viewDidLoad()
  performSegue(withIdentifier: "go" , sender: self)
}

If you want to push your view controller on view did load then just use this code.

let storyBoard : UIStoryboard = UIStoryboard(name: "your_StoryBoard", bundle:nil)
        let nextViewController = storyBoard.instantiateViewController(withIdentifier: "VC_Identifier") as! TargerViewController
        self.navigationController?.pushViewController(nextViewController, animated: true)

OR You can set the target viewcontroller as root viewcontroller by check any condition.

Hope it will helps you out.

Replace viewDidLoad to viewDidAppear solved my problem

override func viewDidAppear() {
    super.viewDidLoad()
    performSegue(withIdentifier: "go" , sender: self)
}

i prefer that don't use segue use as below

let storyboard = UIStoryboard(name: "YourStoryboard", bundle: nil)
 let VC = storyboard.instantiateViewController(withIdentifier: "Your Identifier") as! Your ViewController
 self.present(VC, animated:true, completion:nil)

user this for redirect from One VC To Another VC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM