ios - how to initialize methods in a UIViewController inside of a viewDidLoad method -
there method creating data. method needs called once. structure:
var datacreated : bool? = false override func viewdidload() { super.viewdidload() if datacreated! == false { createdata() self.datacreated = true } }
is right way ensure createdata()
method called once? thank you.
since want createdata
called once per instance of view controller, using viewdidload
place call it. further, since viewdidload
called once per instance of view controller, there no need datacreated
property. can remove that.
override func viewdidload() { super.viewdidload() createdata() }
another option call createdata
init
method of view controller. depends on createdata
needs access. if createdata
method needs access views , outlets, must use viewdidload
.
Comments
Post a Comment