如何将 NSMutableDictionary 从一个 viewController 传递到另一个视图控制器?
How to pass NSMutableDictionary from one viewController to another View controller?
firstviewcontroller.m
@property (nonatomic) NSMutableDictionary *json;
.h
@synthesis json;
viewdidload()
{
nslog(@"%@",json);
}
secondviewcontroller.h
firstviewcontroller *FVC = [[firstviewcontroller alloc]init];
FVC.json = @"My NSMutableDictionary"
这是我的代码,在 firstviewcontrol
NSMutableDictionary
中值为 null。如何解决?
写入您的 "secondViewConroller.h"
文件
@property (nonatomic, Strong) NSMutableDictionary *json;
并像 "firtstViewConroller.m"
那样传递它
NSMutableDictionary *temJSONDic = ....
secondViewConroller *FVC = [[secondViewConroller alloc] initWithNibName:@"secondViewConroller" bundle:nil];
FVC.json = temJSONDic;
[self.navigationController pushViewController:FVC animated:YES];
使用下面的代码使用 [NSBundle mainBundle]
方法加载您的 xib 文件,返回数组中的第一个对象是您的控制器。然后分配你的字典对象,然后使用 navigationcontroller
.
推送
NSArray * array = [[NSBundle mainBundle] loadNibNamed:@"<your xib file name without .xib extension>" owner:self options:nil];
secondViewConroller *cntrl = [array objectAtIndex:0];
cntrl.json = <your dictionary data>;
[self.navigationController pushViewController:cntrl animated:YES];
firstviewcontroller.m
@property (nonatomic) NSMutableDictionary *json;
.h
@synthesis json;
viewdidload()
{
nslog(@"%@",json);
}
secondviewcontroller.h
firstviewcontroller *FVC = [[firstviewcontroller alloc]init];
FVC.json = @"My NSMutableDictionary"
这是我的代码,在 firstviewcontrol
NSMutableDictionary
中值为 null。如何解决?
写入您的 "secondViewConroller.h"
文件
@property (nonatomic, Strong) NSMutableDictionary *json;
并像 "firtstViewConroller.m"
NSMutableDictionary *temJSONDic = ....
secondViewConroller *FVC = [[secondViewConroller alloc] initWithNibName:@"secondViewConroller" bundle:nil];
FVC.json = temJSONDic;
[self.navigationController pushViewController:FVC animated:YES];
使用下面的代码使用 [NSBundle mainBundle]
方法加载您的 xib 文件,返回数组中的第一个对象是您的控制器。然后分配你的字典对象,然后使用 navigationcontroller
.
NSArray * array = [[NSBundle mainBundle] loadNibNamed:@"<your xib file name without .xib extension>" owner:self options:nil];
secondViewConroller *cntrl = [array objectAtIndex:0];
cntrl.json = <your dictionary data>;
[self.navigationController pushViewController:cntrl animated:YES];