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:
i click view 1, , inspect properties , created manually triggered segue view 2
i selected 'show' option, views connected segue under attribute inspector, give storyboard segue , identifier of "gotoview2". there go viewcontroller.swift file, , in viewdidload function. insert performseguewithidentifier code:
self.performseguewithidentifier("gotoview2", sender: self)
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
Post a Comment