NSArrayM 无法识别的选择器错误
NSArrayM unrecognized selector error
我需要一些帮助来理解为什么我会收到 unrecognized selector error
我有一个NSMutableDictionary
@interface CallDetailViewController () {
NSMutableDictionary * thisDictionary;
}
@end
从 MasterTabController 填充
- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
NSLog(@"Check dictinoary: %@", [thisDictionary description]);
}
输出描述表明数据存在
Check dictinoary: (
{
DATEIN = "2015-12-11 13:33:41";
"ETA" = "2015-12-14 13:54:16";
RecordKey = 2961;
Destination = "Some address";
Location = "Some location";
} )
但是当我尝试访问其中的一个对象时:
NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);
我收到以下错误。
-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7a73f9a0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]:
unrecognized selector sent to instance 0x7a73f9a0'
该数组由一个 JSON 值填充,该值 returns 一个名为 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";
}
);
}
);
};
};
}
我做错了什么?
请尝试这样分配
self.detailDictionary = [[dicRecord objectForKey:@"Record"] objectAtIndex:0];
然后像这样访问
NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);
喜欢编程。
- (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]]];
我认为你的问题可能是你没有在将字典设置为另一个对象之前实例化字典。
我需要一些帮助来理解为什么我会收到 unrecognized selector error
我有一个NSMutableDictionary
@interface CallDetailViewController () {
NSMutableDictionary * thisDictionary;
}
@end
从 MasterTabController 填充
- (void) some method {
thisDictionary = [[(MasterTabController *)self.tabBarController detailDictionary] mutableCopy];
NSLog(@"Check dictinoary: %@", [thisDictionary description]);
}
输出描述表明数据存在
Check dictinoary: ( {
DATEIN = "2015-12-11 13:33:41";
"ETA" = "2015-12-14 13:54:16";
RecordKey = 2961;
Destination = "Some address"; Location = "Some location"; } )
但是当我尝试访问其中的一个对象时:
NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);
我收到以下错误。
-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7a73f9a0 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x7a73f9a0'
该数组由一个 JSON 值填充,该值 returns 一个名为 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";
}
);
}
);
};
};
}
我做错了什么?
请尝试这样分配
self.detailDictionary = [[dicRecord objectForKey:@"Record"] objectAtIndex:0];
然后像这样访问
NSLog(@"Destination: %@", [thisDictionary objectForKey:@"Destination"]);
喜欢编程。
- (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]]];
我认为你的问题可能是你没有在将字典设置为另一个对象之前实例化字典。