swift - 无法添加从 Button 到 ViewController 的 Outlet 连接

标签 swift xcode

我正在尝试在 Xcode 中创建一个从我的按钮到我的 UIViewController 的 IBOutlet 连接/引用,但它只是给我“选项”来添加一个 Action 连接。当文本缩放以适合宽度时,我试图利用 viewDidLoad 和 baselineAdjustment 使按钮标签垂直居中,但我没有任何运气。

有没有人有建议或知道我做错了什么?

enter image description here

编辑:为清晰起见添加更多屏幕截图

如果我选择我的主场景 View ,该类是 ViewController 类型。如果我选择相关 Button 所属的 View (它在 ContainerView 中),则它属于 UIViewController 类,并且选项不提供 ViewController 的选择。

enter image description here enter image description here

最佳答案

确保 UIViewController 的子类是正确的类,确保在执行此操作时选择 UIViewController 而不是 View 或安全区域。

enter image description here

如果解决了请告诉我

关于swift - 无法添加从 Button 到 ViewController 的 Outlet 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55711673/

相关文章:

ios - 捕获图像时出现AVCapturePhotoCaptureDelegate错误

iphone - IOS 低功耗蓝牙连接间隔

ios - viewController 没有被正确删除?

ios - 如何旋转 UISegmentedControl 并增加大小以适应任意数量的文本

ios - 检测何时按下 "back to app"

iphone - 锁定 UIDatePicker 列

ios - 在iOS Swift中从设备获取图像的URL路径

swift - 更改组合图表中的 yValue 标签垂直间距(ios-charts)

ios - 查找模拟器上安装的应用程序的路径

xcode - 如何从 Applescript/Automator/Shell 脚本自动创建新的 Xcode 目标