baruma
baruma

Reputation: 9

How do I segue to a new view controller after a short timeout?

I want to show the user a title screen of the app name firstly and then, after about 2 seconds, the view should proceed to a new view controller.

So far, I have a segue with an identifier. I see a lot of tutorials use IBActions/IBOutlets but I'm not sure if I would use one here since there's no single item that would trigger the segue aside from the timeout.

Upvotes: 0

Views: 211

Answers (1)

glyvox
glyvox

Reputation: 58129

Just use DispatchQueue.main.asyncAfter(deadline:) in viewDidLoad. This code triggers the segue with the given identifier after a 2 seconds delay:

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
    self.performSegue(withIdentifier: "your segue's identifier", sender: self)
}

Upvotes: 4

Related Questions