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。怎么解决这个问题?
答案 0 :(得分:1)
写入"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];
答案 1 :(得分:1)
使用以下代码使用[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];