ios - Using viewDidAppear to present a View Controller, re-opening it when it's closed -


in app, i've created new storyboard serves basic tutorial how use features. (instructions.storyboard). storyboard has it's own class - instructionsvc.swift

i want present instructionsvc when mainvc loads within viewdidappear.

it works great. fires on app load it's supposed to. problem occurs when press [close] button on instructions interface. closes vc, fades main screen, , fires instructions vc up.

how can prevent instructions vc loading once it's closed?

func openinstructions() {     let storyboard = uistoryboard(name: "instructions", bundle: nil)     let instructionsview = storyboard.instantiateviewcontroller(withidentifier: "instructionsstoryboardid")     instructionsview.modalpresentationstyle = .fullscreen     instructionsview.modaltransitionstyle = .crossdissolve     self.present(instructionsview, animated: true, completion:nil) }  override func viewdidappear(_ animated: bool) {     openinstructions() } 

and within instructions class, have following action on close button:

@ibaction func closebuttonpressed(_ sender: uibutton) {     let presentingviewcontroller: uiviewcontroller! = self.presentingviewcontroller     presentingviewcontroller.dismiss(animated: true, completion: nil) } 

note - i'd rather not use userdefaults resolve this, because i'm going incorporating similar in other parts of app , don't want resort userdefaults achieve desirable behavior.

thanks in advance buddies!

viewwillappear , viewdidappear called every time view controller's content view becomes visible. includes first time it's rendered , when it's shown again after being covered modal or view controller being pushed on top of in navigation stack.

viewdidload called once when view controller's content view has been loaded, before displayed. when viewdidload called may invoke second view controller.

you might want add instance variable hasbeendisplayed view controller. in viewdidappear, check hasbeendisplayed. if it's false, display second view controller , set hasbeendisplayed true.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -