ios - 如何从 UIView 内部执行 segue

标签 ios swift segue

如何从 UIView 内部正确准备 segue NOT UIViewController

我的 UIViewController 有一个容器 View ,并且在该容器 View 中有一个按钮。

class myInnerView: UIView {
    ...
    func myButton(gesture: UIGestureRecognizer){
        //calling a perform segue from another UIViewController does not recognize the SegueID
        //ViewController().self.showProfile(self.id) -- DOES NOT WORK
    }
}

class ViewController: UIViewController {
    ...
    func showProfile(id: String){
        ...
        self.performSegueWithIdentifier("toViewProfile", sender: self)
    }
}

最佳答案

您的 View 不应处理按钮点击。这应该由 Controller 处理。 (这就是为什么它被称为“ Controller ”,而 UIView 被称为“ View ”的原因)。

MVC as described by Apple .

关于ios - 如何从 UIView 内部执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31080464/

相关文章:

ios - 在同一 View Controller 类之间传递数据

ios - fetchBatchSize 不适用于 NSFetchRequest

swift - 流式套接字服务器端 swift

iOS8/swift : Tab Bar Item getting smaller on click

ios - 如何使用 Swift 的 prepareForSegue 函数指定要准备的 View Controller ?

ios - 缓慢的 UI 更新,添加 Spinner

ios - KeyboardAvoidingView不断调整高度

iphone - XCode 4.3.2 中的自定义字体

ios - 如何修复 GitHub Actions 中的 xcodebuild 错误

swift - Firebase 查询以随机顺序检索数据。数据按autoID组织