我需要一些帮助,了解我为何获得unrecognized selector error
我有NSMutableDictionary
@interface CallDetailViewController () {
NSMutableDictionary * thisDictionary;
}
@end
从MasterTabController中填充
- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
NSLog(@"Check dictinoary: %@", [thisDictionary description]);
}
输出描述显示数据存在
检查dictinoary :( {
DATEIN =“2015-12-11 13:33:41”;
“ETA”=“2015-12-14 13:54:16”;
RecordKey = 2961;
Destination =“Some address”; 位置=“某个位置”; })
但是当我尝试访问其中的对象时:
NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);
我收到以下错误。
- [__ NSArrayM objectForKey:]:无法识别的选择器发送到实例0x7a73f9a0 ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSArrayM objectForKey:]: 无法识别的选择器发送到实例0x7a73f9a0'
从JSON值填充数组,该值返回名为Record的记录数组。返回JSON后,我只提取包含记录的部分。
NSDictionary * dictTowx = [NSDictionary dictionaryWithDictionary:[dictJSON objectForKey:@"ThisResponse"]];
NSDictionary * dictData = [NSDictionary dictionaryWithDictionary:[dictTowx objectForKey:@"Data"]];
NSArray * arrRecordSet = [dictData objectForKey:@"Recordset"];
NSDictionary * dicRecord= [arrRecordSet objectAtIndex:0];
self.detailDictionary = [dicRecord objectForKey:@"Record"];
RAW JSON:
{
ThisResponse = {
Data = {
Recordset = (
{
Record = (
{
DATEIN = "2015-12-11 13:33:41";
"ETA" = "2015-12-14 13:54:16";
RecordKey = 2961;
Destination = "Some address";
Location = "Some location";
}
);
}
);
};
};
}
我做错了什么?
答案 0 :(得分:1)
请尝试像这样分配
self.detailDictionary = [[dicRecord objectForKey:@"Record"] objectAtIndex:0];
然后像这样访问
NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);
享受编程。
答案 1 :(得分:-2)
- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
NSLog(@"Check dictinoary: %@", [thisDictionary description]);
}
尝试替换
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
与
thisDictionary = [[NSMutableDictionary alloc]initWithDictionary: [[{MasterTabController *)self.tabBarController detailDictionary] mutableCopy]]];
我认为你的问题可能是在将字典设置为另一个字体之前没有实例化字典。