Reputation: 1
I am new to XCode/Swift and trying to storyboard my first Quizz app :)
I've read numerous threads of people who have faced the issue i'm facing, but I couldn't draw a parallel to my case. Would anyone know I could get this working ?
Here it goes (see the screenshot for more detail here)
1) First comes a Tab bar. The storyboard I'm working on starts from 1st view
2) Then comes a navigation bar :
However, if I segue from 4th page to 1st, the navigation controllers "disappears".
==> How can I properly segue back to my 1st page without losing the navigation controller ?
Thanks in advance for your support,
Regards, Mathilde
Upvotes: 0
Views: 1079
Reputation: 1
Thanks for your answer. it sounds pretty straightforward, but when I run this piece of code, nothing happens while clicking on the back button.
Not sure what's going wrong. I'll keep you posted when I find it...
Here how it looks like in my code. My 1st VC is called "FirstViewController"
import UIKit
class endQuizA1ViewController: UIViewController {
@IBAction func back(_ sender: UIButton)
{
if let FirstViewController = self.navigationController?.viewControllers.first {
self.navigationController?.popToViewController(FirstViewController, animated: true)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Upvotes: 0
Reputation: 3302
Connect your 'Back' button via IBAction to method inside your 4th view controller and then use navigation controller popToViewController
method. Example:
@IBAction func backButtonTapped(_ button: UIButton) {
if let firstViewController = self.navigationController?.viewControllers.first {
self.navigationController?.popToViewController(firstViewController, animated: true)
}
}
Upvotes: 1