I have one view controller with table view. I want know, how it possible to make, that when user tap on one of the row it will show another view controller for 5 seconds. Here is my code. I’ve created a objc func:
@objc func moveHome() {
store.dispatch(NavigationAction(destination: .home, direction: .forward))
}
And in the method didSelectRowAt:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let st = UIStoryboard(name: "SchoolsMain", bundle: nil)
let vc = st.instantiateViewController(withIdentifier: "SchoolsPreHomeViewController") as? SchoolsPreHomeViewController
UserDefaults.standard.set(testData[indexPath.row].name, forKey: "orgNameForSplash")
self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.moveHome), userInfo: nil, repeats: false)
}
It’s works, but not like I want. Now when we select each of the row, we waiting for 5 seconds and then another view controller shows. But I want that we tap and it will show at the moment for 5 seconds.
2
Answers
Set the timer of 5 seconds in the ViewController (SchoolsPreHomeViewController) that you need to show and on the completion of those 5 seconds call the method in which you will need to write the code to dismiss/pull it (SchoolsPreHomeViewController).
Feel free to ask if any doubt.
Latest Edit SchoolsPreHomeViewController.swift
you can do it like this.