In a ViewController, there is ViewDidLoad
to know when the VC has loaded.
For a UIView, what method do i have to use when the view loaded?
Would this method be called with any init?
edit: No XIB, just programmatically.
viewDidLoad is called when the ViewController has loaded its view hierarchy into memory. This is the point where you can perform your customized initialisation for your view controller. For instance, if your view controller has a UILabel and you want to set a custom text to it, this is the point where you do that.
viewDidLoad: Whatever processing you have that needs to be done once. viewWilLAppear: Whatever processing that needs to change every time the page is loaded. Labels, icons, button titles or most dataInputedByDeveloper usually don't change.
An object that manages the content for a rectangular area on the screen.
viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.
If you load it from a XIB
file, the awakeFromNib
method will be called once loading finishes:
override public func awakeFromNib() { super.awakeFromNib(); // ... loading logic here ... }
Update; In the case of no XIB, you will probably have to infer it using one of the methods from the Observing View-Related Changes area of the docs (for example, didMoveToSuperview
). However, a better way is to send a message to your views from the view controller's viewDidLoad
method if possible.
You can use willMove(toSuperview newSuperview: UIView?)
import UIKit final class myView: UIView { override func willMove(toSuperview newSuperview: UIView?) { super.willMove(toSuperview: newSuperview) //Do stuff here } }
Apple Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With