How to pop back to root view from a 2nd view?

可紊 提交于 2019-12-11 03:04:17

问题


I have connected 3 views (root, 1st, 2nd) together using 2 modal segues in apple watch storyboard.

1) In root view: Once the "save" button is pressed, 1st modal view will be displayed

2) In 1st modal view: Once the "500" button is pressed, 2nd modal view will be displayed. (I can press cancel button to pop back to root view)

3) In 2nd modal view: Once the "saved" button is pressed, I want to go back to root view. How to do this?

--> I don't want to press cancel button twice to go back to the root view.


回答1:


I found this is posible only if your "Logout" screen is really the root. If it is not (because there were screens before it) then you can not use the next method.

The method I'm talking about is

[WKInterfaceController reloadRootControllersWithNames:(NSArray *) contexts:(NSArray *)]

Call this method when you catch the action from your "Save" button in your second modal. It will load the pages you specify in the first array (here you have to add the identifier of your root controller) with the contexts of the second array (here you deliver an object if you want your root controller to realize it was called from the second modal instead of being called because the app is opened by the first time).

Hope this helps.




回答2:


i have achieved your scenario.

1. Use push pushControllerWithName: method to push to another view controller to navigate. Do not use present or modal to navigate to another view controller. 
2. Create one NSNotificationCenter observer in your Watch first controller. 
3. Create and assign WatchSession delegate in WCWatchDelegate. 
4. Whenever watchsession delegate calls, post notification center.
5. Now, final step is whenever your notification method calls, use [self popToRootController]; and you will be redirect on your root controller.

I have followed these step and i'm succeeded. Accept Answer if it works for you. Dont forget to vote up!!!


来源:https://stackoverflow.com/questions/28739473/how-to-pop-back-to-root-view-from-a-2nd-view

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