Why is viewDidUnload called less often than viewDidLoad?

前端 未结 3 471
醉梦人生
醉梦人生 2021-02-03 11:19

I put NSLog(@\"%@::%@\", [[self class] description], NSStringFromSelector(_cmd)); in both viewDidLoad and viewDidUnload of a view controll

3条回答
  •  情书的邮戳
    2021-02-03 11:58

    I imagine that in the cases where -viewDidUnload wasn't called, the view controller was released.

    1. viewDidLoad: controller loads view
    2. viewDidUnload: memory warning, controller unloads view
    3. viewDidLoad: controller loads view again
    4. -: controller gets released, doesn't explicitly unload the view

    You and up with 2 -viewDidLoad calls and 1 `-viewDidUnload' call.

    Maybe also put a NSLog into the -dealloc method and see if the number of -dealloc and -viewDidUnload calls combined matches the number of -viewDidLoad calls.

提交回复
热议问题