I’ve a GameViewController
that segues to a NavigationController
after which to SettingsViewController
. All the pieces works as anticipated.
I wish to add a < Finished
or < Again
button to the left facet of the nav bar, to return to the GameViewController
as soon as completed. How do I do that programmatically?
The UI is fully created programmatically, since most of it’s primarily based in SpriteKit
. The Interface Builder has principally nothing aside from the empty controllers.
In GameViewController
set the worth so it may be accessed later:
class GameViewController: UIViewController
{
override func viewDidLoad()
{
tremendous.viewDidLoad()
...
scene.viewController = self
...
}
}
Then within the GameScene
of GameViewController
retrieve and carry out the segue:
class GameScene: SKScene
{
weak var viewController: UIViewController?
...
// Carry out the segue when an SKSpriteNode is touched
`viewController?.performSegue(withIdentifier: "GoToSettingsSegue", sender: viewController)`
}
Lastly, in SettingsViewController
, create the UI programmatically and add a title:
class SettingsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{
override func viewDidLoad()
{
tremendous.viewDidLoad()
configure()
title = "Settings"
...
}
}
Based mostly on some analysis up to now, I do know that the Again/Finished navigation merchandise belongs to the earlier UIViewController
, not the present one. So, in my case, it must be added to the GameViewController
, to not the SettingsViewController
, proper?
Another analysis additionally introduced up the priority of eradicating views from the stack so it does not decelerate an excessive amount of for those who commute a number of occasions.
How do I add that programmatically to GameViewController
and/or GameScene
and set the motion/goal to principally segue again from SettingsViewController
to GameViewController
? I am new to iOS growth so I am not fully positive.