I have a Tab bar Controller (with a bottom menu) and also a top menu. The problem is that I don't want to link the yellow and green views to the tab bar (because the user is going to change the views using the top menu rather than the bottom menu).
I'm having a problem that every time I click the buttons a new instance of the view is going to stack (so I end up having something like V1 -> V2 -> V3 -> V2 -> V4 and so on)
My partial solution is to make something like this:
@IBAction func yellowViewButtonAction(_ sender: AnyObject)
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "YelloViewController") as! YelloViewController
if let viewControllers = navigationController?.viewControllers {
for viewController in viewControllers {
// some process
if viewController is YelloViewController {
print("View is on stack")
}
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "YelloViewController") as! YelloViewController
self.navigationController?.pushViewController(controller, animated: false)
}
}
I can see that the view is on navigation stack because the if
statement inside the for
is true
. The question is, how can I retrieve it instead of pushing a new instance of the same view? (Because besides the huge memory problem that this present I also lose any data I had on the view).
I want to keep everything on the stack intact.
Example:
V1 -> V2 -> V3 -> V4 (current view)
If I go back to V1 from V4 I still want to have V4, V3 and V2 on the navigation controller stack.
Another question is that if this solution is something that Apple might refuse.
I appreciate any help.