I have a viewController (HomeViewController()) which is embedded into a NavigationCotroller and I have a horizontal CollectionView with 6 cells at the bottom of my viewController and I have implemented the delegate method didSelectItemAt indexPath: IndexPath
Now when I select the any of the cell it will navigate to the respective viewController(self.navigationController?.pushViewController(ViewControllerInstance, animated: true)
) lets call it "NewVC1()" as I am using pushViewController, it will create a back button for me and if I click on the back button it will pop back to the previous viewController. It is general scenario and working as expected.
In my case after selecting the collectionViewCell in "HomeViewController()" I will go the "NewVC1()" and in there I have the same CollectionView as I have in the previous viewController(HomeViewController()) and now if I select any of the cells in the present viewController(NewVC1()) again I will navigate to the respective viewController(NewVC2()) same like before using pushViewController and Now, if I click on the back button in the "NewVC2()", I don't want to go to the "NewVC1()" and instead of that I want to go to "HomeViewController()".. How can I achieve this, is there any possibility of doing this?
I hope you understand what I am trying to convey and I am sorry if you can't understand my bad english and also sorry as I think this question looks very confusing..
EDIT:
Symbolically:
let VC1 = HomeViewController()
let VC2 = NewViewController1()
let VC3 = NewViewController2()
Navigation: VC1 -> VC2 -> VC3 and if want to come back to VC1,
general case:
VC3 -> VC2 and VC2 -> VC1 (possible)
my case:
VC3 -> VC1 (?)
Instead of pushing from
VC2
toVC3
use setViewControllers. Then when you press back button fromVC3
it will come back toVC1
Use this code in
VC2
collectionView didSelectItemAt