您好,我是 IOS Watchkit 开发的新手。
我需要在用户点击表格行时传递数据。我已经尝试过使用 segue
和使用 pushControllerWithName
两种方法,甚至在方法中尝试了 presentControllerWithName
-(void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex
{
[self contextForSegueWithIdentifier:@"navigare" inTable:self.tbl rowIndex:rowIndex];
//And Tried following
[self pushControllerWithName:(NSString *)@"ProfileInterfaceController" context: rowValue];
}
这里有什么帮助吗?
最佳答案
您在从 ProfileInterfaceController 访问“rowValue”时遇到问题吗?或者您只是不确定如何完成此操作?
WatchKit 允许您使用 presentControllerWithName:Context: 方法将数据发送到带有 segue 的 WKInterfaceController。
名称 - 是在 Interface Builder 中分配给目标 WKInterfaceController 的名称(不是文件名称或任何其他名称)。
Context - 是您用来发送数据的 NSDictionary 参数。
当目标 WKInterfaceController 初始化时,awakeWithContext: 方法被调用,并且您的上下文字典可供使用。
在您提供的代码片段中,很难理解“rowValue”。这需要在发送前包装在 NSDictionary 对象中。
查看 Apple's Framework Reference for more information
不相关,但值得注意 - 在 Objective C 中使用 NSString 字面量语法(@"This is a string")时,无需添加 (NSString *)。
关于ios - 当用户在 Table View 行上切换到 Watchkit 中的另一个详细界面 Controller 时需要将数据传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28387575/