如何制作“添加”导航栏上的按钮做了什么? [英] How do I make the "Add" button on a navigation bar do something?

查看:178
本文介绍了如何制作“添加”导航栏上的按钮做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以自从上次iPhone编程冒险以来我已经休息了几年,而且我显然已经忘记了上次学到的大部分内容。加上XCode看起来完全不同,所以我也必须重新学习它。

So I've taken a few years off since my last iPhone programming adventure, and I've apparently forgotten most of what I learned last time. Plus XCode looks totally different, so I'm having to re-learn that as well.

我使用了Storyboard功能来布局我的下一个UI项目。主屏幕嵌入在导航控制器中,我在主屏幕上有四个按钮。按任意按钮可以加载子视图;我还没有超越子视图。总而言之,我现在所拥有的是主/主屏幕,以及四个独立的子视图,每个子视图都可以通过点击主/主屏幕上的按钮来访问。到目前为止,这一切都很有效。

I've used the Storyboard feature to lay out the basic UI of my next project. The main screen is embedded in a Navigation controller, and I have four buttons on the main screen. Pressing any button causes a sub-view to be loaded; I haven't gotten past the sub-views yet. So, in summary, what I have right now is a main/home screen, plus four separate sub-views, each of which is accessed by tapping a button on the main/home screen. This all works peachy so far.

所以。在我的第一个子视图 - 称之为人物屏幕 - 我有一个带有添加功能([+])的条形按钮项目。我正在尝试做的是点击添加按钮时出现一个动作表。不幸的是,没有任何控制 - 从这个按钮拖动到我项目中任何.h / .m文件中的任何位置都会产生一个小弹出窗口,我可以设置一个动作/插座。

So. On my first sub-view - call it the "People" screen - I have a bar button item with the "Add" function ([+]) on it. What I'm trying to do is get an Action Sheet to appear when the add button is tapped. Unfortunately, no amount of control-dragging from this button to any location in any .h/.m file in my project will produce the little pop-up where I can set up an action/outlet.

我在这里做错了什么?

推荐答案

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addItem:)];

self.navigationItem.rightBarButtonItem = addButton;

然后你必须添加一个名为addItem的void方法,你必须在其中定义做什么你想要添加按钮(在你的情况下是一个动作表)。

Then you have to add a void method called "addItem", in which you have to define what do you want the Add button to do(in your case an actionsheet).

这篇关于如何制作“添加”导航栏上的按钮做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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