且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

向 UINavigationController 中的所有视图控制器添加相同的按钮

更新时间:2023-12-05 17:20:28

导航项是每个视图控制器.导航栏从当前正在构建其视图的视图控制器的导航项中绘制其内容,该视图对应于导航控制器堆栈顶部的视图控制器.

The navigation item is per view controller. The navigation bar draws its contents from the navigation item of the view controller whose view it's currently framing, which corresponds to the view controller at the top of the navigation controller's stack.

您基本上需要每个视图控制器在其导航项中粘贴一个取消按钮.您可以执行以下任何操作:

You basically need each view controller to stick a cancel button in its navigation item. You can do any of the following:

  • 将代码复制粘贴到所有相关的视图控制器中.
  • 将代码移动到实用函数或类中并调用它.
  • 为所有相关视图控制器创建一个通用超类,以处理为其子类设置取消按钮.