【问题标题】:How to pop back to root view from a 2nd view?如何从第二个视图弹回根视图?
【发布时间】:2015-02-26 10:06:16
【问题描述】:

我在 Apple Watch 故事板中使用 2 个 modal segues 将 3 个视图(root、1st、2nd)连接在一起。

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

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

3) 在第二个模态视图中:一旦按下“保存”按钮,我想返回根视图。如何做到这一点?

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

【问题讨论】:

  • 使用 [self.navigationcrontroller poptoRootviewcontroller animated:yes];
  • 你展示了模态视图,所以你不能使用 popToRootViewController,你可以使用 Unwind Segues spin.atomicobject.com/2014/10/25/ios-unwind-segues
  • 嗨@Anbu.Karthik 我在 WKInterfaceController 类型的第二个模式视图“SavedInterfaceController”中添加了 self.popToRootController()。但在按下“保存”按钮后,它只保留在第二个模式视图上。我正在使用模态转场而不是推转转场。请帮忙。 @.@
  • 嗨@HuyNghia,这是苹果手表...故事板没有展开segue...或者我错过了什么?
  • @user1872384 很抱歉我对 WacthKit 一无所知 :(

标签: ios storyboard segue apple-watch


【解决方案1】:

我发现只有当您的“注销”屏幕确实是根时才可行。如果不是(因为之前有屏幕),那么您不能使用下一个方法。

我说的方法是

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

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

希望这会有所帮助。

【讨论】:

  • 忘了提一下,如果您在该屏幕之前有屏幕并且您不能使用此方法(因为它会破坏导航并“忘记”之前调用的那些屏幕),您应该隐藏元素从您的第一个模式中重新加载 UI 而不是打开第二个模式。因此,当您按取消时,您将返回“注销”屏幕。如果对您有帮助,请将答案标记为正确!
【解决方案2】:

我已经实现了您的方案。

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!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多