I'm making this small game with swift and the game is set up using the viewDidLoad. Each day the game is suppose to be slightly different, but that depends on that the viewDidLoad runs. So let's say a user plays at day 1 and keeps the game active to day 2, the game won't function on day 2 since the viewDidLoad wasn't run. For the game to function properly I need to run the VieDidLoad each time "applicationDidBecomeActive", to make sure it runs as it should.
I've tried to do like this:
func applicationDidBecomeActive(application: UIApplication)
{
myViewController?.viewDidLoad()
}
I also tried to wrap my code that is inside viewDidLoad like this and run it in applicationDidBecomeActive. But that doesn't do it.
override func viewDidLoad()
{
func refreshView()
{
//all the code goes here
}
}
Any idea what I could do?
Set your view controller to listen applicationDidBecomeActive
notifications and run the configuration method when it receives it
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "refreshView:",
name: UIApplicationDidBecomeActiveNotification,
object: nil)