如何将NSMutableDictionary从一个viewController传递到另一个View控制器?
问题描述:
firstviewcontroller.m如何将NSMutableDictionary从一个viewController传递到另一个View控制器?
@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]
方法和返回数组的第一个对象的厦门国际银行文件是控制器。然后分配您的字典对象,然后使用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' – Subramanian
用故事板的财产申报的代码和Segue公司,你可以通过赛格瑞委托 – GeneCode