ios - Swift Changing View with performSegueWithIdentifier / programmatically -


so trying programmatically change views when condition triggered.

i have created simplistic project, whereby want change view 2 view 1, once view 1 has loaded. in reality, there logical operation checks if variable true, invokes performseguewithidentifier function, keep simple possible have removed code.

the steps have performed are, firstly create 2 views: showing 2 views

i click view 1, , inspect properties , created manually triggered segue view 2 connecting manual segue

i selected 'show' option, views connected segue connected manual segue under attribute inspector, give storyboard segue , identifier of "gotoview2". naming segue there go viewcontroller.swift file, , in viewdidload function. insert performseguewithidentifier code:

self.performseguewithidentifier("gotoview2", sender: self) 

adding performseguewithidentifier code

however, when run code. view 2 not load, , view 1 appears in simulator.

any , explanation appreciated.

i have had same problem attempting perform segue inside viewdidload function, , error comes seems view attempting load segue not in window hierarchy.

changing call viewdidappear seemed fix issue mentioned in other post: whose view not in window hierarchy (note language objective-c not swift, can translated).

it seems have careful @ point in view lifecycle want change view controller - @ viewdidload views in storyboard not available.

btw, without having conditional in there, segue fired (and load view controller) every time view loaded!


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -