Swift - Bar Button Item支持功能

时间:2022-06-01 22:13:58

I have a Bar Button Item in the navigation bar of the view (Edit Button). Unlike other buttons (UIButton), I am unable to press ctrl and drag to view controller to create a function to handle it. I want when the button is pressed, a function body to execute.

我在视图的导航栏中有一个条形按钮项(编辑按钮)。与其他按钮(UIButton)不同,我无法按ctrl并拖动来查看控制器以创建处理它的函数。按下按钮时我想要一个要执行的功能体。

How can I link them?

我该如何链接它们?

2 个解决方案

#1


1  

Just show the assistant editor

只需显示助理编辑

Swift  -  Bar Button Item支持功能

and use the document outline (the left bar that list all your view controllers and relative items) for select the bar button item, then CTRL & drag or drag with your right mouse button:

并使用文档大纲(列出所有视图控制器和相关项目的左侧栏)选择栏按钮项,然后用鼠标右键拖动并拖动或拖动:

Swift  -  Bar Button Item支持功能

Automatically for bar button item Xcode link as action:

自动为条形按钮项Xcode链接为动作:

Swift  -  Bar Button Item支持功能

#2


0  

Make sure the button is selected (The view should darken a bit everywhere expect where the button is) and open up the Utilities area. Open the Connections inspector in utilities (an arrow pointing to the right) and under Triggered Segues drag from the circle to your code and create your action.

确保选中该按钮(视图应该在按钮所在的任何位置变暗)并打开“实用程序”区域。打开实用程序中的Connections检查器(指向右侧的箭头),然后在Triggered Segues下从圆圈拖动到代码并创建操作。

#1


1  

Just show the assistant editor

只需显示助理编辑

Swift  -  Bar Button Item支持功能

and use the document outline (the left bar that list all your view controllers and relative items) for select the bar button item, then CTRL & drag or drag with your right mouse button:

并使用文档大纲(列出所有视图控制器和相关项目的左侧栏)选择栏按钮项,然后用鼠标右键拖动并拖动或拖动:

Swift  -  Bar Button Item支持功能

Automatically for bar button item Xcode link as action:

自动为条形按钮项Xcode链接为动作:

Swift  -  Bar Button Item支持功能

#2


0  

Make sure the button is selected (The view should darken a bit everywhere expect where the button is) and open up the Utilities area. Open the Connections inspector in utilities (an arrow pointing to the right) and under Triggered Segues drag from the circle to your code and create your action.

确保选中该按钮(视图应该在按钮所在的任何位置变暗)并打开“实用程序”区域。打开实用程序中的Connections检查器(指向右侧的箭头),然后在Triggered Segues下从圆圈拖动到代码并创建操作。