如何从第二个视图回弹到根视图?

时间:2015-02-26 10:06:17

标签: ios storyboard segue apple-watch

我使用Apple watch storyboard中的2个模态 segues将3个视图(root,1st,2nd)连接在一起。

1)在根视图中:按下“保存”按钮后,将显示第一个模态视图

2)在第一模态视图中:按下“500”按钮后,将显示第二模态视图。 (我可以按取消按钮弹回根视图)

3)在第二模态视图中:按下“已保存”按钮后,我想返回到根视图。怎么做?

- >我不想按两次取消按钮返回根视图。

imgae

2 个答案:

答案 0 :(得分:1)

我发现只有当你的“退出”屏幕确实是根目录时才有可能。如果不是(因为之前有屏幕),那么你就不能使用下一个方法。

我正在谈论的方法是

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

当您从第二个模态中的“保存”按钮捕捉到操作时,请调用此方法。它将在第一个数组中加载你指定的页面(这里你必须添加根控制器的标识符)和第二个数组的上下文(如果你希望你的根控制器意识到它是从第二个模态而不是被调用,因为应用程序是第一次打开的。)

希望这有帮助。

答案 1 :(得分:0)

我已经实现了你的方案。

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!!!
相关问题