在WatchKit中的prepareForSegue等价物

Hol*_*dad 14 ios uistoryboard watchkit

我有一个带2个按钮的界面,它们都调用相同的界面,但信息不同.在传统的界面上我使用prepareForSegue,但我不知道WatchKit上的等价物是什么.

Tia*_*ida 34

您可以通过两种方式执行此操作:

在故事板中,您在segue中设置了一个标识符:

在此输入图像描述

然后你可以使用contextForSegueWithIdentifier:

- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier {
     if ([segueIdentifier isEqualToString:@"yourIdentifier"]) {
        return aDictionaryWithYourInformation;
     }
}
Run Code Online (Sandbox Code Playgroud)

或者您可以通过代码传递带有上下文的信息,其中:

[self pushControllerWithName:@"YourViewController"
                     context:aDictionary];
Run Code Online (Sandbox Code Playgroud)

这个上下文是一个字典,您可以访问该字典 - (void)awakeWithContext:(id)context


Nik*_* M. 10

对于Watchkit中的segue导航,WKInterfaceController中有两种方法:

override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
        return //your object
    }
Run Code Online (Sandbox Code Playgroud)

和表格

override func contextsForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> [AnyObject]? {
      return  //your object
    }
Run Code Online (Sandbox Code Playgroud)

你可以得到func awakeWithContext(context: AnyObject?)你正在推送的接口控制器传入的对象