【问题标题】:Trigger segue programmatically on watchOS在 watchOS 上以编程方式触发 segue
【发布时间】:2016-12-02 03:19:46
【问题描述】:

我正在开发 watchOS 3 应用。

我有一个连接到按钮的 segue,它工作正常。现在我想以编程方式触发它。

收到手机消息后,我想将手表导航到特定视图,但我似乎无法通过 WatchKit 调用 self.performSegue 方法。

有什么办法吗?

【问题讨论】:

    标签: ios swift3 apple-watch watchos-3


    【解决方案1】:

    在 WatchKit 中,您不能以编程方式执行 segue。相反,您需要使用pushController(withName:context:)presentController(withName:context:)presentController(withNames:contexts:)

    确保在 InterfaceBuilder 中为您的 WKInterfaceControllers 设置标识符。

    如果您需要将数据传递给控制器​​,请查看 contextForSegue(withIdentifier: String) contextsForSegue(withIdentifier: String)

    【讨论】:

      【解决方案2】:

      您现在可以通过编程方式执行 segue。

      或者,您可以通过调用 pushController(withName:context:) 以编程方式启动推送转换

      source

      例如

      @IBAction func buttonTapped() {
          pushController(withName: "identifierOfNextInterfaceController", context: nil)
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多