简体   繁体   English

如何使用 Swift 将 storyboard 中的“已发送事件”连接到 Xcode 13.3 中的事件处理程序 function?

[英]How do I connect "Sent events" in storyboard to an event handler function in Xcode 13.3 using Swift?

I recently updated the OS as well as Xcode version on my macbook, and I'm not sure if I am doing anything wrong.我最近在我的 macbook 上更新了操作系统以及 Xcode 版本,我不确定我是否做错了什么。 I have only sparingly worked with older version of Xcode and Objective C before.我以前只很少使用旧版本的 Xcode 和 Objective C。

From a button that I added in storyboard I want to connect the "touch up inside" user event to a function as shown below, but it is not letting me:从我在 storyboard 中添加的按钮,我想将“内部修饰”用户事件连接到 function,如下所示,但它不允许我:

在此处输入图像描述

I have tried clicking and dragging from the sent event radio button in storyboard to the function name (as shown above, which worked when connecting this button's referencing output to an IBOutlet variable previously) as well as dragging to the radio button next to the function name, as shown below:我尝试单击并从 storyboard 中的已发送事件单选按钮拖动到 function 名称(如上所示,之前将此按钮的引用 output 连接到 IBOutlet 变量时有效)以及拖动到 function 名称旁边的单选按钮, 如下所示:

在此处输入图像描述

Nothing happened in both cases and it is not letting me connect the user event to the desired function. Is there anything different I need to do in Xcode 13.3?在这两种情况下都没有发生任何事情,它不允许我将用户事件连接到所需的 function。在 Xcode 13.3 中我需要做什么不同的事情吗? Is there any way to do this by editing a file rather than using the GUI?有没有办法通过编辑文件而不是使用 GUI 来做到这一点?

  1. First of all, in storyboard, if you click on a button, check the last tab of the inspector if any of the actions are already set up.首先,在 storyboard 中,如果您单击一个按钮,检查检查器的最后一个选项卡是否已经设置了任何操作。

  2. There might be also a connection issue or an Xcode bug, so I suggest restarting it.也可能存在连接问题或 Xcode 错误,因此我建议重新启动它。

  3. There is an another way to hook up Sent Events.还有另一种连接已发送事件的方法。 Select your button, with CTRL key make the connection to the ViewController icon on top of the screen (see screenshot) and select your desired method. Select 你的按钮,用 CTRL 键连接到屏幕顶部的 ViewController 图标(见截图)和 select 你想要的方法。

在此处输入图像描述

If that method does not come up there, it means your Storyboard might be corrupted, or there is a class name mismatch for the View Controller itsef.如果该方法没有出现,则意味着您的 Storyboard 可能已损坏,或者视图 Controller 本身的 class 名称不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM