我有一个具有三个 Controller 的 watch 应用程序。主 Controller ,另一个带有 TableView 的 Controller ,最后一个是设置 Controller 。在设置 Controller 中我有一个开关。当它的值发生更改时,该值将存储到 bool 变量中。我想将此变量的值发送到第一个 Controller ,这样当我滑回第一个 Controller 时,该值将被发送到那里。是否可以?我怎样才能做到这一点?
最佳答案
是的,这是可能的。您必须使用contextForSegueWithIdentifier
。您必须从此方法返回数据,并在目标类(在您的情况下为“第一个 Controller ”)中访问该数据。
你可以这样实现:
// In settings controller
override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
return self.currentValue
// In first controller
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
if let value: String = context as? String {
print(value)
}
关于ios - WatchKit:将数据从第三个 Controller 传递到初始 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32137864/