为什么 IB Action 设置为 exit as object?

Why is the IB Action set to exit as object?

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

图像link在下面编辑到 Imigur。

This is the connection to ViewController2

This is what occurs when I connect the IBAction to ViewController2

You can see there is no action option for the connection in this image.

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

当您附加 @IBAction(或 @IBOutlet)时,您不想将它们附加到视图控制器上的 Exit

按照以下步骤添加 @IBAction:

1) 确保你的 View Controller 的 class 链接到你的文件,然后进入 Assistant Editor确定您选择了自动

2) 按住 Control (^) 并将按钮拖动到您的 ViewController class.

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

应该看起来像这样:


如有疑问,请告诉我!

单击有问题的顶部栏 ViewController(屏幕上显示的内容的概述),单击左上角的图标(称为视图控制器)。

在右键单击“Show The Identity Inspector”图标,您应该会看到 class。将文本更改为 'ViewController'。希望它应该自动填充。

这将解决问题。