Proper use of loadView and viewDidLoad with UIViewController without nibs/xibs

后端 未结 2 489
自闭症患者
自闭症患者 2020-12-01 07:55

When I program without a nib, I am under the impression that I need to call loadView to initialize my view, like this:

- (id)initWithNibName:(NSString *)nibNa         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 08:31

    The answer by Firoze Lafeer is correct, I just want to show how to force load the view property the correct way:

    (void)self.view;
    

    You should not do this! If you must, you are doing something wrong, but do not call -loadView and -viewDidLoad yourself at any circumstances.

提交回复
热议问题