【发布时间】:2017-09-20 20:28:29
【问题描述】:
通常(当使用 XCode 故事板创建 UI 时)ctrl-drag 会创建到另一个视图控制器的 segue。与 UIButton 完美搭配。
但是如果 UIButton 位于自定义视图(即 UIView 的子类)内,如何使用 ctrl-drag 创建一个 segue?
import UIKit
// class KachelView is used several times in
// the main storyboard on entry panel.
@IBDesignable
class KachelView: UIView {
// normal stuff here
// XIB file contains a UIButton that is
// to ignite a segue in the outer view
}
有没有办法在情节提要中做到这一点,还是我应该在代码中做到这一点?
【问题讨论】:
-
你不能在情节提要中从你想要的按钮上按住 ctrl-drag 吗?
-
UIButton 是自定义 UIView 的一部分。这似乎可以防止将它用作普通的 UIButton 和 ctrl-drag 的东西。不工作
-
使用@Edgar 的答案加上一些额外的麻烦解决了问题。我从 UIControl 继承而不是 UIView。所以我可以使用 UIKit 的通知器/观察者机制在 KachelView 中创建一个可以在故事板类中订阅的事件。然后按代码继续。
标签: swift xcode storyboard segue custom-view