ios - 当用户在 Table View 行上切换到 Watchkit 中的另一个详细界面 Controller 时需要将数据传递

标签 ios objective-c watchkit apple-watch wkinterfacetable

您好,我是 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/

相关文章:

ios - XCode 4.2 在多个目标设置上崩溃

iphone - UIView 动画问题,当尝试不对图像进行动画处理时

ios - 如何让自定义委托(delegate)工作

ios - 将基本语言设置为 Settings.Bundle iOS

ios - 错误 ITMS-90363 : "Invalid Info.plist key. The key ' CFBundleIcons~ipad' in bundle MyApp. 应用程序……

swift - 我如何将 "popToRootController"与 "pushController"结合起来

ios - 添加一些数据后复选标记重复....当我进行检查时

ios - 如何改变视频播放的速度

ios - 推送通知 Firebase 导致崩溃

ios - WatchOS 唤醒 iOS 应用程序以使用配对的蓝牙耳机开始录音