【发布时间】:2015-04-17 09:14:35
【问题描述】:
我有一个带有 2 个按钮的界面,它们都调用相同的界面,但信息不同。在传统界面上我使用 prepareForSegue,但我不知道 WatchKit 上的等效界面是什么。
【问题讨论】:
标签: ios uistoryboard watchkit
我有一个带有 2 个按钮的界面,它们都调用相同的界面,但信息不同。在传统界面上我使用 prepareForSegue,但我不知道 WatchKit 上的等效界面是什么。
【问题讨论】:
标签: ios uistoryboard watchkit
您可以通过两种方式做到这一点:
在你的故事板中,你在你的 segue 中设置一个标识符:
然后你可以使用contextForSegueWithIdentifier:
- (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier {
if ([segueIdentifier isEqualToString:@"yourIdentifier"]) {
return aDictionaryWithYourInformation;
}
}
或者您可以通过代码传递带有上下文的信息,使用:
[self pushControllerWithName:@"YourViewController"
context:aDictionary];
此上下文是一个字典,您可以在- (void)awakeWithContext:(id)context 中访问此字典
【讨论】:
Watchkit 中的 segue 导航在 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?) 中获取你正在传递的对象
【讨论】:
在 WatchKit 中,你可以使用它来调用 WKInterfaceController:
[self pushControllerWithName:@"YourControlName"
context:[self contextForSegueWithIdentifier:@"YourControlName"]];
【讨论】:
对于表格,如下所示:
override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
return //your object
}
【讨论】: