【问题标题】:UIStoryboardSegue Subclass identify Kind of segueUIStoryboardSegue 子类识别类型的segue
【发布时间】:2017-05-15 14:58:09
【问题描述】:
class CustomSegue: UIStoryboardSegue {

    override init(identifier: String?, source: UIViewController, destination: UIViewController) {
        super.init(identifier: identifier, source: source, destination: destination)
    }

    override func perform() {

        self.source.navigationController?.pushViewController(self.destination, animated: true)

    }

}

在上面的代码中,我重写了 segue 的行为。 它应该使用pushViewController,只有当类型是 Show (e.g.: Push) 对于其他类型它应该执行它可以执行的默认行为。

如何在子类perform()方法中找到segue的Kind?

即

       override func perform() {

            if kind==Push { 
              self.source.navigationController?.pushViewController(self.destination, animated: true)
            } else {
              super.perform()
            }

        }

【问题讨论】:

    标签: ios uinavigationcontroller uistoryboardsegue


    【解决方案1】:

    在 storyboard 中,选择 segue 作为自定义 segue 并选择 kind 作为自定义 segue,对于默认行为只需选择 show segue(例如推送)

    【讨论】:

    • 但是在代码 perform() 中,我们怎么知道它是一个自定义行为。我只想修改它的 Show(e.g Push)
    • 你不能从表演中得到善意。您需要在故事板而不是代码中创建不同的 segue。一个像自定义 segue 这样具有推送转换的 segue 和其他应该是默认 segue。
    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2016-11-22
    • 2020-06-19
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 2017-06-19
    相关资源
    最近更新 更多