3

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.

imgae

user1872384
  • 6,886
  • 11
  • 61
  • 103
  • use [self.navigationcrontroller poptoRootviewcontroller animated:yes]; – Anbu.Karthik Feb 26 '15 at 10:08
  • You present modal view sothat you can't use popToRootViewController, you could use Unwind Segues http://spin.atomicobject.com/2014/10/25/ios-unwind-segues/ – Huy Nghia Feb 26 '15 at 10:08
  • Hi @Anbu.Karthik I've added self.popToRootController() in the 2nd modal view "SavedInterfaceController" which is of type WKInterfaceController. But it just remain on the 2nd modal view after pressing "Saved" button. I'm using modal segue instead of push segue btw. Please help. @.@ – user1872384 Feb 26 '15 at 10:19
  • Hi @HuyNghia this is apple watch... the storyboard does not have unwind segue... or am I missing something? – user1872384 Feb 26 '15 at 10:20
  • @user1872384 I'm so sorry I don't know any thing about WacthKit :( – Huy Nghia Feb 26 '15 at 10:22
  • may be this link useful for u http://stackoverflow.com/questions/1792858/how-do-i-get-the-rootviewcontroller-from-a-pushed-controller – Anbu.Karthik Feb 26 '15 at 10:25
  • @Anbu.Karthik thx for your help but I need a solution for push segue. =.='' – user1872384 Feb 26 '15 at 10:37
  • @user1872384 -- can u say clearly, i am also not working in watch kit, but i surely support to u – Anbu.Karthik Feb 26 '15 at 10:39
  • How can I explain it in a way others can understand? Basically I want to know how to pop to root controller using multiple modal segue for apple watch. – user1872384 Feb 26 '15 at 13:21
  • I would suggest to set rootViewController again, Otherwise you can't navigate directly to rootViewController while using PresentModal. – Dipen Panchasara Feb 26 '15 at 14:03

2 Answers2

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.

jastrada
  • 384
  • 1
  • 8
  • Forgot to mention, in case you have screens before that one and you can't use this method (because it breaks the navigation and "forgets" those screens that were called before) you should hide the elements from your first modal and reload the UI instead of opening a second modal. So when you press cancel you go back to the "logout" screen. Please mark answer as correct if it helped you! – jastrada Feb 26 '15 at 15:56
0

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!!!
Pratik Patel
  • 1,393
  • 12
  • 18