0

My app has navigational control i have 2 UIViewController. viewCon1 is initial view controller.

I then Pushed the viewCon2 in navigational control. Now i want to access variables and func of viewCon1 in viewCon2 without static logic.

I used static func logic to get Self of viewCon1 i.e. WK_DshBrd

let dashBoardObj = WK_DshBrd.getDasBoardObject() as! WK_DshBrd
            dashBoardObj.unReadMsgsCaseArr?.append(caseNo)

But i get following error on runtime

    Could not cast value of type 'Watch_Extension.WK_DshBrd' (0x7f1e0) to 'Watch_Extension.WK_DshBrd' (0x7ed78).

How can i cast it or achieve required functioanlity in alternative way?

Hassy
  • 5,068
  • 5
  • 38
  • 63
  • I got a better answer http://stackoverflow.com/questions/33820903/get-wkinterfacecontroller-reference-while-pushing-interfacecontroller – Hassy Nov 20 '15 at 10:41

1 Answers1

0

You can use prepareForSegue method in your first controller. There you can retrieve second view controller like this:

let controller = segue.destinationViewController as! SecondViewController
controller.data = "test" //PASS DATA HERE

Eventually you can even pass reference to first view controller here, but it's not recommended.

edit:

As you're using watchkit you can pass data in context variable. Check you this tutorial: http://www.tech-recipes.com/rx/52810/how-do-i-pass-data-between-screens-in-my-apple-watch-apps/

Makalele
  • 7,431
  • 5
  • 54
  • 81