loadView: functions in UIView iOS

后端 未结 1 1238
小鲜肉
小鲜肉 2021-01-02 13:39

I don\'t understand the mechanism of loadView: function (this function is in UIView).

I created a project as below:

  • First, I created a iPh
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-02 14:09

    loadView: is only invoked when the view property is nil. Use this when creating views programmatically. default: create a UIView object with no subviews. For ex -

    - (void)loadView 
    { 
        UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
        [view setBackgroundColor:color]; 
        self.view = view; 
        [view release]; 
    }
    

    By implementing the loadView: method, you hook into the default memory management behavior. If memory is low, a view controller may receive the didReceiveMemoryWarning message. The default implementation checks to see if the view is in use. If its view is not in the view hierarchy and the view controller implements the loadView: method, its view is released. Later when the view is needed, the loadView: method is invoked again to create the view.

    Not sure why you want to use loadView: but you can do just as much in viewDidLoad:

    Reference -

    1. Why is this iPhone program not calling -loadView?
    2. loadView

    Hope this helps.

    0 讨论(0)
提交回复
热议问题