I have a SongNamesViewController with navigationController embedded. When a song is chosen from a list I open PlaySongViewController and add to the navigationController using following function:
func openPlaySongViewController() {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let playSongViewController = storyBoard.instantiateViewController(withIdentifier: "playSongViewController")
self.navigationController?.pushViewController(playSongViewController, animated: true)
}
Now, a message arrives via remote push-notification. The user taps on the push-notification icon and then I display the song using "openPlaySongViewController()" function. If another push-notification comes and then I display another PlaySongViewController on top of existing PlaySongViewController.
Current flow: (NavigationController)->SongNamesViewController>PlaySongViewController->PlaySongViewController
How do I remove the existing PlaySongViewController that is on the navigationController before adding a new instance of PlaySongViewController?
I tried the following but the PlaySongViewController that is on navigationController does not go away.
for viewController in self.navigationController!.viewControllers {
if viewController.isKind(of: PlaySongViewController.self) {
viewController.removeFromParent()
}
}