DismissViewControlers when Multiple ViewControllers/segues are present

随声附和 提交于 2019-12-12 01:57:48

问题


I have the following scenario with three ViewController's

There is a button in VC2.

User Already Logged-in Case : Clicking on this button in VC2 will take you to VC3 , i.e I have a push-segue from VC2 to VC3

User Not Already Logged-in Case: Clicking on the button , will take you to LoginVC(modal segue) ,On successfull-login ,User will go to VC3((modal segue) and then the user can go back to VC2 on clicking back button. i.e, VC2 will present LoginVC , LoginVC will present VC3.

Question-1 : How do I go about dismissing VC's in this manner. Per my knowledge of dismissing VC's , parent delegate method is responsible for dismissing child VC. However I have a chain of Vc's forming a loop. On Successful login, we go from loginVC to VC3. When going back to VC2 from VC3, who should dismiss VC3?

Question-2: VC2 - VC3 is a push segue. LogicVC to VC3 is a modal segue. Is this correct ?


回答1:


I suggest you to rethink your flow a little bit. Doesn't really make sense why your LoginVC presents VC3 in modal segue. Rather you should have a model segue from VC2 to LoginVC in case login is required, and if the login is success, dismiss this LoginVC, which you can dismiss in the LoginVC itself by [self dismissViewControllerAnimated:YES completion:nil]; and present the VC3 in a navigation segue manner.

It is not always the parent who is responsible for dismissing the child VC. The child VC's can dismiss themselves. If you still want to achieve in your manner, then your VC3 should first dismiss itself, and then, depending upon whether you want to show your LoginVC or not, you can dismiss the LoginVC in the completion block.

About your question 2, really makes no sense. Are you asking us how your system flow should look like? You can have any kind of segue which matches your requirements.

Let me know if this helps.



来源:https://stackoverflow.com/questions/24845118/dismissviewcontrolers-when-multiple-viewcontrollers-segues-are-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!