ios - 如何在 WatchKit 中使用 "context"传递多个对象

标签 ios objective-c watchkit

我正在使用以下代码将数据传递给我的第三个 Controller :

[self presentControllerWithName:@"ThirdView" context:MyArray];

问题是,我想传递的不仅仅是一个简单的数组。如果可能,我想传递一个单独的字符串和另一个数组,并且我不想将字符串或另一个数组添加到“MyArray”。

有没有不同的方法来解决这个问题,还是我只是重组这段代码?

最佳答案

您可以使用要传递的数据创建自定义对象,也可以将数据捆绑在字典或数组中。在swift中,您也可以使用元组。

这是一个字典示例:

NSDictionary *myData = @{
    @"MainArray" : MyArray,
    @"MyString" : @"string",
    @"AnotherArray" : anotherArray
};
[self presentControllerWithName:@"ThirdView" context: myData];

数组示例:
NSArray *myData = @[MyArray, @"string", anotherArray];
[self presentControllerWithName:@"ThirdView" context: myData];

关于ios - 如何在 WatchKit 中使用 "context"传递多个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31378335/

相关文章:

ios - 使用仪器了解 Objective-C 中的保留计数(泄漏)

watchkit - watch 操作系统 2 : Run code when a user puts on his watch

ios - 在 swift/objective-c 中将任意二进制数据编码/解码为字符串

ios - 从另一个 View ios 导航时,键盘不会关闭

iphone - UIButton Transition - 跨屏幕运行

ios - 从父应用程序发送消息到 WatchKit 接口(interface)

watchkit - 苹果 watch : Creating mail app style rows in WKInterfaceTable

ios - 插页式广告后更改场景 (SpriteKit)

ios - 如何为CGPath的绘图部分制作动画

ios - CGFloat 有奇怪的默认值