I have been following along a video tutorial that is teaching me about programmatically creating an iOS App without storyboards.
It is going well and I like most of the things about it, however I have a slight problem.
I am only half way through and I have noticed a potential problem with memory, the way the tutorial has shown me is that for every next view I present it like so:
let ChooseCategoryController = ChooseCategoryViewController()
present(ChooseCategoryController, animated: true, completion: nil)
and then I present another one from the view there. And to go back I am also presenting another view. I noticed when running the app that the memory usage is going up and up.
Is there a way, that when I present a new view, I can detect what views are open and close all the others?
I thought maybe something in the completion section but I am struggling as I am rather new.
Thanks in advance.
Update1
After trying the solution below and adding in the self. as xcode asked me to I have this code:
dismiss(animated: false, completion: {
self.present(DisplayQuestionsViewController(), animated: true, completion: nil)
})
I get this warning:
Warning: Attempt to present < triviaGameApp.DisplayQuestionsViewController: 0x7fb39481ce00 > on < triviaGameApp.ChooseCategoryViewController: 0x7fb392e019f0 > whose view is not in the window hierarchy!
If it is relevant. This code is fired on the click of a UICollectionView cell on ChooseCategoryViewController()
Update 2:
I have changed the code now to the following:
dismiss(animated: false, completion: {
self.parent?.present(DisplayQuestionsViewController(), animated: true, completion: nil)
})
As mentioned by the poster below. The current view controller does now dismiss however it does not load the new one.