NSCFDictionary - 无法识别的选择器发送到实例

时间:2015-06-20 15:07:16

标签: ios objective-c debugging unrecognized-selector

我有两种模式 - 模式1和模式2,可以通过中央按钮切换。在模式之间切换允许用户查看两种不同类型的聚类注释。

我可以轻松地从模式1切换到模式2,但是当我切换回模式1时,我得到了这个讨厌的错误

-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fb1308cca50

我打开我的代码并在TBClusteredAnnotations.m(脚本I' m用于群集化)。我有以下与componentsSeparatedByString相关的代码段:

 TBQuadTreeNodeData TBDataFromLine(NSString *line)

{
    NSString *separator=@">>>>>>>>";

    NSArray *components = [line componentsSeparatedByString: separator];
    double latitude = [components[0] doubleValue];
    double longitude = [components[1] doubleValue];

    TBUserInfo* userInfo = malloc(sizeof(TBUserInfo));

    NSString *userName = [components[2] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    userInfo->userId = malloc(sizeof(char) * userName.length + 1);
    strncpy(userInfo->userId, [userName UTF8String], userName.length + 1);

    NSString *userId = [components [3] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    userInfo->userImage = malloc(sizeof(char) * userId.length + 1);
    strncpy(userInfo->userImage, [userId UTF8String], userId.length + 1);

    return TBQuadTreeNodeDataMake(latitude, longitude, userInfo);
}

但是我在MainViewController中使用以下代码加载我的注释:

-(void)annotationsmode1:(NSMutableArray*)marr
{
    if(marr.count>0)
    {
        NSMutableArray *newMarr1=[NSMutableArray new];
        NSString *separatestuff=@">>>>>>>>";
        for(NSMutableDictionary *dic in marr)
        {
            NSString *newStr=[NSString stringWithFormat:@"%@%@",[dic[@"latitude"] isEqualToString:@""]?@" ":dic[@"latitude"],separatestuff];
            newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"longitude"] isEqualToString:@""]?@" ":dic[@"longitude"],separatestuff];
            newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"id"] isEqualToString:@""]?@" ":dic[@"id"],separatestuff];
            newStr=[NSString stringWithFormat:@"%@%@",newStr,[dic[@"image"] isEqualToString:@""]?@" ":dic[@"image"]];

            [newMarr1 addObject:newStr];

        }
        //NSLog(@"NEW Array: %@",newMarr);
        [self.coordinateQuadTree buildTree:newMarr1];
    }
}

-(void)annotationsmode2:(NSMutableArray*)marr
{
    if(marr.count>0)
    {
        NSMutableArray *newMarr=[NSMutableArray new];
        NSString *separatestuff2=@">>>>>>>>";
        for(NSMutableDictionary *dic in marr)
        {
            NSString *newStr=[NSString stringWithFormat:@"%@%@",[dic[@"lat"] isEqualToString:@""]?@" ":dic[@"lat"],separatestuff2];
            newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"lang"] isEqualToString:@""]?@" ":dic[@"lang"],separatestuff2];
            newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"id"] isEqualToString:@""]?@" ":dic[@"id"],separatestuff2];
            newStr=[NSString stringWithFormat:@"%@%@",newStr,[dic[@"image"] isEqualToString:@""]?@" ":dic[@"image"]];
            [newMarr addObject:newStr];
        }

        //NSLog(@"NEW Array: %@",newMarr);
        [self.coordinateQuadTree buildTree:newMarr];
    }

}

更新:这是使用TBDataFromLine的代码块

- (void)buildTree:(NSMutableArray *)lines
{
    @autoreleasepool {

        NSInteger count = lines.count - 1;

        TBQuadTreeNodeData *dataArray = malloc(sizeof(TBQuadTreeNodeData) * count);
        for (NSInteger i = 0; i < count; i++) {
            dataArray[i] = TBDataFromLine(lines[i]);
        }
        //TBBoundingBox world = TBBoundingBoxMake(19, -166, 72, -53);
        TBBoundingBox world =  TBBoundingBoxMake(0,0,100,100);
        _root = TBQuadTreeBuildWithData(dataArray, count, world, 4);
    }
}

我已经在这个问题上工作了好几个小时了,但仍然没有任何线索。

更新:这是调试人员的日志

    2015-06-20 19:40:23.759 MapProject[13426:395344] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fdf93775680'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000112699c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001121c3bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001126a10ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00000001125f713c ___forwarding___ + 988
    4   CoreFoundation                      0x00000001125f6cd8 _CF_forwarding_prep_0 + 120
    5   MapProject 0x000000010f469ac4 TBDataFromLine + 84
    6   MapProject 0x000000010f46a36f -[TBCoordinateQuadTree buildTree:] + 191
    7   MapProject 0x000000010f3d2503 -[MMViewController findSpot:] + 771
    8   UIKit                               0x0000000110a52da2 -[UIApplication sendAction:to:from:forEvent:] + 75
    9   UIKit                               0x0000000110b6454a -[UIControl _sendActionsForEvents:withEvent:] + 467
    10  UIKit                               0x0000000110b63919 -[UIControl touchesEnded:withEvent:] + 522
    11  UIKit                               0x0000000110a9f998 -[UIWindow _sendTouchesForEvent:] + 735
    12  UIKit                               0x0000000110aa02c2 -[UIWindow sendEvent:] + 682
    13  UIKit                               0x0000000110a66581 -[UIApplication sendEvent:] + 246
    14  UIKit                               0x0000000110a73d1c _UIApplicationHandleEventFromQueueEvent + 18265
    15  UIKit                               0x0000000110a4e5dc _UIApplicationHandleEventQueue + 2066
    16  CoreFoundation                      0x00000001125cd431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x00000001125c32fd __CFRunLoopDoSources0 + 269
    18  CoreFoundation                      0x00000001125c2934 __CFRunLoopRun + 868
    19  CoreFoundation                      0x00000001125c2366 CFRunLoopRunSpecific + 470
    20  GraphicsServices                    0x000000011444da3e GSEventRunModal + 161
    21  UIKit                               0x0000000110a51900 UIApplicationMain + 1282
    22  MapProject 0x000000010f474c2f main + 111
    23  libdyld.dy
)
libc++abi.dylib: terminating with uncaught exception of type NSException

2 个答案:

答案 0 :(得分:0)

添加一个异常断点,它将精确到达崩溃发生的那一行。还要检查&#39; line&#39;因为它被更改为字典但你编码期望它  成为一个字符串

答案 1 :(得分:-3)

NSArray或NSMutableArray上没有[]运算符。

你需要这个:

for (NSInteger i = 0; i < count; i++) {
    dataArray[i] = TBDataFromLine([lines objectAtIndex:i]);
}

在NSArray *上使用[]有效地表现得像&#34; line&#34;实际上是一个指向NSMutableArray实例数组的指针,而你想要从它所指向的数组中获取其中一个项目。