ios - 如何在 UINavigationBar 的右侧设置两个按钮?

标签 ios objective-c uinavigationbar uibarbuttonitem

我已经制作了一个标准的主从应用程序(使用 Xcode 模板)。我修改了它,现在当我单击第一个表格 View 的一个单元格时,应用程序会显示另一个表格 View (这是详细信息,因为它是由单击的单元格值过滤的)。 在标准表格 View 中,我会在 UINavigationBar 上遇到这种情况:

Edit Table title + (for adding new items)

我也需要 UINavigationBar 的默认后退按钮。是否有可能并允许这样做?从图形上看应该是这样的:

< Back Table title Edit +

您知道在顶部栏中显示 3 个按钮(返回 - 编辑 - 添加)和标题的任何其他布局吗?

抱歉没有发布图片,在此先感谢。

附言我想知道是否可以使用内置的后退按钮和编辑按钮(我的意思是系统自动放入导航栏的按钮)来完成我要求的事情。

最佳答案

您需要设置右侧栏项目数组以设置右侧的栏按钮...

这里是 2 个自定义按钮的代码,用于设置右侧的栏按钮项目......你可以使用默认按钮而不是这个

UIButton *btnabout =  [UIButton buttonWithType:UIButtonTypeCustom];
btnabout.frame = CGRectMake(0,8,30,30);
[btnabout setBackgroundImage:[UIImage imageNamed:@"about.png"] forState:UIControlStateNormal];
[btnabout addTarget:self action:@selector(callselector) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *about = [[UIBarButtonItem alloc] initWithCustomView:btnabout];
about.tintColor = [UIColor whiteColor];


UIButton *btnsetting =  [UIButton buttonWithType:UIButtonTypeCustom];
btnsetting.frame = CGRectMake(0,8,30,30);
[btnsetting setBackgroundImage:[UIImage imageNamed:@"setting"] forState:UIControlStateNormal];
[btnsetting addTarget:self action:@selector(SettingData) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *setting = [[UIBarButtonItem alloc] initWithCustomView:btnsetting];
setting.tintColor = [UIColor whiteColor];

self.navigationItem.rightBarButtonItems =[NSArray arrayWithObjects:setting, about, nil];
// --- or if you want left side ----
//  self.navigationItem.leftBarButtonItems =[NSArray arrayWithObjects:setting, about, nil];

关于ios - 如何在 UINavigationBar 的右侧设置两个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31612471/

相关文章:

ios6 - iOS 6 中的导航栏看起来像 iOS 7 中的导航栏

ios - Interface Builder 文件中的未知类 _TtC8<appName>20MasterViewController

ios - 使用__IPHONE_7_0并响应toSelector

iphone - iOS 应用程序缺少屏幕截图

ios - 在 Swift 语法中监听 Objective-C 回调

ios - 在 UIToolbar 上创建左箭头按钮(如 UINavigationBar 的 "back"样式)

ios - 以 associatedtype 作为参数类型的 Swift 协议(protocol)

ios - NSPredicate Core Data iOS 中的子查询

ios - 创建具有最大大小并在添加更多项目时删除项目的 NSMutableArray 的最佳途径是什么?

ios - 使用 TitleView 在 IOS 的导航栏上添加 2 行文本