如何在UINavigationBar的右侧设置两个按钮? [英] How can I set two buttons on the right side of an UINavigationBar?

查看:441
本文介绍了如何在UINavigationBar的右侧设置两个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个标准的Master-Detail应用程序(带有Xcode模板).我对其进行了修改,现在,当我单击第一个表格视图的一个单元格时,该应用程序将显示另一个表格视图(这是详细信息,因为已通过单击的单元格值进行过滤). 在标准表视图中,我会在UINavigationBar上遇到这种情况:

I have made a standard Master-Detail application (with the Xcode template). I modified it, and now when I click one cell of the first table view the app shows another table view (which is the detail because is filtered by the clicked cell value). In a standard table view I would have this situation on the UINavigationBar:

Edit Table title + (for adding new items)

我也需要UINavigationBar的默认后退按钮.是否可以这样做?用图形表示就是这样:

I need the default back button of UINavigationBar too. Is it possible and allowed to do this? Graphically it would be like this:

< Back Table title Edit +

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

Do you know any other layout to display 3 button (back - edit - add) plus title all in the top bar?

对不起,您无法发布图片,谢谢.

Sorry for not posting images, Thanks in advance.

P.S.我想知道是否可以使用内置的后退按钮和编辑按钮(我的意思是系统自动将其放到导航栏上的按钮)完成我要问的事情.

P.S. I'd like to know if it is possible to do the things I'm asking with built-in back button and edit button (I mean those that the system puts automatically to the navigation bar).

推荐答案

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

you need to setup array of right bar items to set up bar buttons right side...

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

Here is the code of 2 custom button to setup bar button items right side...you can use default button instead of this

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];

这篇关于如何在UINavigationBar的右侧设置两个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆