当我们设置 self.navigationItem.hidesBackButton = YES; 时实际上调用了什么方法;

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

我很好奇当我们设置 self.navigationItem.hidesBackButton = YES/NO; 时实际上调用了什么方法。我很好奇,因为 属性 不是 方法 ,当我们将实际 运行 分配给任何值时背景,因此它可以立即隐藏或显示后退按钮。我一直在想有一个 运行 循环 会不断检查这样的东西。

来自 Apple 文档

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

因此,由于 UIKit 基于 MVC,当您设置此 属性 时,当前视图的模型会发生变化。

然后,在下一个运行循环中,视图重绘,那你看是不是隐藏了

这个调用背后的方法被iOS自动调用重绘,可能是一些私有的重绘方法。

希望对您有所帮助