Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewDidLoad for UIView?

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.

like image 980
Luda Avatar asked Apr 22 '13 11:04

Luda


People also ask

What is the viewDidLoad method?

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.

What is the difference between viewDidLoad and viewWillAppear?

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.

What is UIView life cycle?

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.

Does viewWillAppear get called before viewDidLoad?

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.


2 Answers

Try

-awakeFromNib method

Or in xib set the view property hidden for your subview

like image 185
Lithu T.V Avatar answered Sep 20 '22 02:09

Lithu T.V


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.

like image 34
Rebecca Avatar answered Sep 18 '22 02:09

Rebecca