我有一个带有两个按钮的界面,它们都调用相同的接口,但使用不同的信息。在传统的界面上,我使用prepareForSegue,但是我不知道WatchKit上的等效方法。
我有一个带有两个按钮的界面,它们都调用相同的接口,但使用不同的信息。在传统的界面上,我使用prepareForSegue,但是我不知道WatchKit上的等效方法。
你可以有两种方法来做到这一点:
在你的storyboard中,你可以在segue中设置一个标识符:
然后你可以使用contextForSegueWithIdentifier
:
- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier {
if ([segueIdentifier isEqualToString:@"yourIdentifier"]) {
return aDictionaryWithYourInformation;
}
}
或者您可以通过代码传递带有上下文的信息,例如:
[self pushControllerWithName:@"YourViewController"
context:aDictionary];
这个上下文是一个字典,你可以在- (void)awakeWithContext:(id)context
中访问它。
在 Watchkit 中进行转场导航有两种方法可以使用,分别是 WKInterfaceController 中的两个方法:
override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
return //your object
}
并且适用于表格
override func contextsForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> [AnyObject]? {
return //your object
}
在推送的界面控制器中,你可以通过func awakeWithContext(context: AnyObject?)
方法获取传递给它的对象。
[self pushControllerWithName:@"YourControlName"
context:[self contextForSegueWithIdentifier:@"YourControlName"]];
For tables it's the following:
override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
return //your object
}