uiviewcontroller - Basic Transitioning Between View Controllers in Swift -


i working implement code move between 2 view controllers, vc1 , vc2.

vc1 toggles between 2 skviews, , vc2 displays simple things in uiview.

vc1 , vc2 both in main storyboard.

vc1 displayed first, @ point in skscene segues vc2:

let currentviewcontroller: uiviewcontroller = (self.view?.window?.rootviewcontroller)! currentviewcontroller.performsegue(withidentifier: "vc1tovc2", sender: currentviewcontroller) 

after short delay in vc2, segues vc1:

self.performsegue(withidentifier: "vc2tovc1", sender: self) 

these segues work.

then, same code above (using same segue):

let currentviewcontroller: uiviewcontroller = (self.view?.window?.rootviewcontroller)! currentviewcontroller.performsegue(withidentifier: "vc1tovc2", sender: currentviewcontroller) 

...the 2nd time not work segue vc1 vc2. there's no exception, vc2 not display.

i found other posts don't address issue, example: * swift segue not working? - suggests ui updating has in main thread, , 1 shows how in swift 3 - how dispatch_sync, dispatch_async, dispatch_after, etc in swift 3? --- same result * other posts suggested using view controller's .show or .present method --- same result

any thoughts/guidance?

i solved using delegate other posts have mentioned, eg how call method viewcontroller in gamescene. delegate allows skscene object call / run code in view controller. allows view controller perform segue instead of trying perform segue skscene object (not sure that's possible, perform segue skscene object). here's simple tutorial https://useyourloaf.com/blog/quick-guide-to-swift-delegates/ if you're not familiar delegates in swift. can post more details if anyone.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -