5

我正在创建一个需要通知的应用程序。我创建了一个带有开关的设置页面,用于切换应用程序的通知。我尝试使用@IBAction 将开关链接到 ViewController2,但它一直将对象连接到 Exit,而不是 ViewController。我真的很沮丧,因为@IBAction 不会保持连接。我不确定发生了什么,但如果我能得到帮助,那就太棒了。

这些图像在下面链接到 Imigur。

这是到 ViewController2 的连接

这就是我将 IBAction 连接到 ViewController2 时发生的情况

您可以看到此图像中的连接没有操作选项。

4

3 回答 3

11

当您附加@IBActions(或@IBOutlets)时,您不想将它们附加到ExitView Controller 上。

请按照以下步骤添加@IBAction

1)确保您的 View Controller 的类已链接到您的文件,然后进入Assistant Editor确保您选择了Automatic

使用故事板

2)按住Control (^)并拖动按钮到您的ViewController班级。

拖动项目

3)将按钮添加为@IBAction. -也建议使用UIButton作为发件人,而不是Any

连接动作

应该如下所示:

代码 发送事件


如果您有任何问题,请告诉我!

于 2018-08-02T00:20:16.940 回答
7

问题可能是您假设您可以形成从一个视图控制器场景中的 UISwitch 到另一个视图控制器的操作连接。你不能。您只能在情节提要的同一场景内的视图控制器和界面之间形成出口和动作。

于 2018-08-02T00:13:37.797 回答
0

Click on the top bar of your problematic ViewController (the overview of what is getting displayed on screen), click the top left icon (called View Controller).

On the right click "Show The Identity Inspector" icon and you should see class. Change the text to 'ViewController'. Hopefully it should auto fill.

This will solve the problem.

于 2020-11-20T15:58:46.040 回答