在两个视图控制器之间传递字典? [英] Passing a dictionary between two viewcontrollers?
问题描述
我有一个应用程序,其中我有一个webservice调用,返回数据作为字典。我想在另一个视图控制器中访问此字典,以将值加载到表中。
I have an application in which I have a webservice call that returns data as a dictionary. I want to access this dictionary in another view controller for loading the values into a table.
任何人都可以演示如何将此响应字典从一个视图控制器传递到另一个视图控制器?
Can anybody demonstrate how to pass this response dictionary from one view controller to another?
推荐答案
您可以在 AnotherViewController
中定义 NSDictionary
属性,并从上一个控制器设置它。我将在下面给出一个简单的例子。
You could define an NSDictionary
property in your AnotherViewController
and set it from the previous controller. I'll give a brief example below.
//.h
@interface AnotherViewController {
NSDictionary *data;
}
@property(nonatomic,retain) NSDictionary *data;
@end
//.m
@implementation AnotherViewController
@synthesize data;
现在从电流控制器初始化 AnotherViewController
Now from the current controller, after initializing AnotherViewController
you set the dictionary before presenting it.
AnotherViewController *controller = [[AnotherViewController alloc] init];
controller.data = myCurrentDictionary;
现在 AnotherViewController
有 $
Now AnotherViewController
has a data
property with the value of the previous controller.
希望这有助于。
这篇关于在两个视图控制器之间传递字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!