iphone - iOS: Which function to override when I need to do something after the view is visible to the user? -


so first thing app list of movies api. i'm trying handle if there's network issue. currently, in viewdidload method, call "updateapiinfo", contains following code:

if self.movies == nil {             print("stuff went wrong")             let alert = uialertcontroller(title: "network error", message: "there nework error.\nyou must connected internet use flicks.", preferredstyle: uialertcontrollerstyle.alert)             alert.addaction(uialertaction(title: "exit", style: uialertactionstyle.default, handler: {(uialertaction) in                 uicontrol().sendaction(selector("suspend"), to: uiapplication.sharedapplication(), forevent: nil)             }))             self.presentviewcontroller(alert, animated: true, completion: nil) } 

when viewdidload calls updateapiinfo, message:

warning: attempt present <uialertcontroller: 0x7fad10e3ad80> on <flicks.moviesviewcontroller: 0x7fad10e35cc0> view not in window hierarchy! 

when call updateapiinfo user refreshing, error pops expected.

i'm assuming viewdidload gets called before view gets displayed user, guess causing error. there method can stick code in after view displayed user, problem can presumably fixed?

you need use viewdidappear: make sure view in window hierarchy.

there's pretty explanation of order in methods called here: what process of uiviewcontroller birth (which method follows which)?


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -