What is the difference between loadView and viewDidLoad?

I know that there seems to be an exact duplicate of this question: iPhone SDK: what is the difference between loadView and viewDidLoad? However, I read this question and still have not received a complete answer. I do not use IB as the user interface is dynamic.

So, I have to create self.view and then add subviews to loadView.

or do I need to create self.view in loadView and add subviews to viewDidLoad? #

+3
source share
6 answers

When you load a view from NIB and want to do further customization after startup, use viewDidLoad.

( Interface Builder), loadView.

+15

subview viewDidLoad. , loadView, , .

Apple:

, , :

1.

  * Some part of your application asks for the view in the view

.

2.

  * If the view is not currently in memory, the view controller calls its loadView

.

3.

  * The loadView method does one of the following:

        If you override this method, your implementation is

non-nil view.

        If you do not override this method, the default implementation uses 

nibName nibBundle , nib. nib , nib, .

        If no nib file is available, the method creates an empty UIView object 

.

4.

  * The view controller calls its viewDidLoad method to perform any

.

+2

. IB, UIViewController . loadView!

loadView .

, viewDidLoad. :

- (void)loadView {
    CGRect frame = [[UIScreen mainScreen] applicationFrame];
    baseView = [[UIView alloc] initWithFrame:frame];
    [self setView:baseView];
    [baseView release];
}

! . . viewDidLoad , .

- (void)viewDidLoad {
    [super viewDidLoad];

    msg = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 320, 50)];
    [msg setText:@"Your profile is empty!"];
    [[self view] addSubview:msg]; // hey, I have done my view at loadView, so I have it now
    [msg release];
}

:)

+2

subviews viewDidLoad. , 100% , .

0

loadView - , ( , self.view).

viewDidLoad . , ( ), , .

viewDidLoad: " , . , nib loadView".

loadView: " , ".

0

Use viewDidLoadto initialize views and construct. And use loadViewif you don't have Nib / Xib and you want your ViewController to have a custom (not UIView) look.

0
source

Source: https://habr.com/ru/post/1758382/


All Articles