ios - 导航栏按钮不出现

标签 ios xcode

我想通过代码将按钮添加到我的导航栏,但我没有看到它们。我认为这可能与我的导航栏位于 UIView 内有关。

我在 viewDidLoad 中的代码:

[super viewDidLoad];

 self.navigationItem.leftBarButtonItem = self.editButtonItem;

 UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
 self.navigationItem.rightBarButtonItem = addButton;

界面构建器:

Interface builder

如有任何帮助,我们将不胜感激!

最佳答案

您不应该直接在 View 层次结构中添加导航栏。相反,添加一个导航 Controller ,将您的 View Controller 作为导航 Controller 的根 Controller ,并将导航 Controller 设置为 Storyboard的初始 Controller (或作为 segues 等的目标 Controller )。

关于ios - 导航栏按钮不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25673356/

相关文章:

ios - 如何从 itunes connect 或 xcode 关闭 NewsStand 功能?

ios - 如何在 SwiftUI 中引用外部 iOS 系统状态更新?

iphone - JSON 图像解析/前缀 URL

iphone - iPhone 版 UnRar 库 - 受密码保护的 Rar 文件

ios - 错误 "HTML tag ' ul' 需要结束标记 FIREventNames.h"

xcode - 构建 ipa 时列出了 2 个具有相同名称的 Ad Hoc Distribution 配置文件

ios - IOS 上的 NSTimer 和电池充电

ios - podspec 警告 : no rule to process file for architecture i386

ios - 从 Github 添加 mongoSwift 驱动程序后尝试运行项目时,会显示 libbson-1.0.0.dylib : mach-o, 但不是为 iOS 模拟器构建的错误

ios - Xcode 为同一个应用构建不同的环境