我有一个应用程序,其中有一个 web 服务调用,该调用将数据作为字典返回。我想在另一个 View Controller 中访问此字典以将值加载到表中。
谁能演示如何将这个响应字典从一个 View Controller 传递到另一个 View Controller ?
最佳答案
您可以在 AnotherViewController
中定义一个 NSDictionary
属性,并从之前的 Controller 中设置它。下面我将给出一个简短的例子。
//.h
@interface AnotherViewController {
NSDictionary *data;
}
@property(nonatomic,retain) NSDictionary *data;
@end
//.m
@implementation AnotherViewController
@synthesize data;
现在从当前 Controller 开始,在初始化 AnotherViewController
之后,您可以在呈现之前设置字典。
AnotherViewController *controller = [[AnotherViewController alloc] init];
controller.data = myCurrentDictionary;
现在 AnotherViewController
有一个 data
属性,其值为之前的 Controller 。
希望这对您有所帮助。
关于objective-c - 在两个 View Controller 之间传递字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10991743/