What is the viewDidLoad
for UIView
?
I have a UIView
with xib. I would like to hide one of it's subviews when it is loaded. I tried to use this.
- (id)initWithCoder:(NSCoder *)aDecoder{ .... _theView.hidden = YES; }
But the subview _theView
is nil at this point.
This answer didn't help me, becouse at moment of creating the UIViewController
, the UIView
is not created yet. It is created programaticly, later on.
viewDidLoad is the method that is called once the MainView of a ViewController has been loaded. This is called after loadView is called.In the image you can see the MainView and other views within it.
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.
Every UIView with enabled Auto Layout passes 3 steps after initialization: update, layout and render. These steps do not occur in a one-way direction. It's possible for a step to trigger any previous one or even force the whole cycle to repeat.
viewWillAppear(_:)Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.
Try
-awakeFromNib
method
Or in xib set the view property hidden for your subview
AwakeFromNib
is called only if the view loaded from nib file. layoutSubviews
is called for all views, you can add bool _loaded = yes;
in the layoutSubviews
function and know if the view loaded.
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