Search code examples
iosuinavigationbaruinavigationitemrunloop

What method actually got called when we set self.navigationItem.hidesBackButton = YES;


I am curious what method actually got called when we set self.navigationItem.hidesBackButton = YES/NO;. I'm curios because the property is not a method, when we assign to any value what actually running on the background, so it can hide or show Back Button immediately. I have been thinking there is a Run Loop which keep checking stuff like this.


Solution

  • From Apple Document

    The View Drawing Cycle The UIView class uses an on-demand drawing model for presenting content. When a view first appears on the screen, the system asks it to draw its content. The system captures a snapshot of this content and uses that snapshot as the view’s visual representation. If you never change the view’s content, the view’s drawing code may never be called again. The snapshot image is reused for most operations involving the view. If you do change the content, you notify the system that the view has changed. The view then repeats the process of drawing the view and capturing a snapshot of the new results.

    When the contents of your view change, you do not redraw those changes directly. Instead, you invalidate the view using either the setNeedsDisplay or setNeedsDisplayInRect: method. These methods tell the system that the contents of the view changed and need to be redrawn at the next opportunity. The system waits until the end of the current run loop before initiating any drawing operations. This delay gives you a chance to invalidate multiple views, add or remove views from your hierarchy, hide views, resize views, and reposition views all at once. All of the changes you make are then reflected at the same time

    So, As UIKit is based On MVC, when you set this property,the model of that present view change.

    Then, in the next run Loop, the view will redraw,then you see it is hidden or not.

    The methods behind this call are auto called by iOS to redraw,maybe some private redraw method.

    Hope this will helps you