У меня есть два режима - режим 1 и режим 2, которые можно переключать с помощью центральной кнопки. Переключение между режимами позволяет пользователю видеть два разных типа кластеризованных аннотаций.NSCFDictionary - Непризнанный селектор отправлен в экземпляр
можно переключаться из режима 1 в режим 2 легко, но когда я переключиться обратно в режим 1 Я получаю эту неприятную ошибку
-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fb1308cca50
Я открываю свой код и в TBClusteredAnnotations.m
(сценарий I Используется для кластеризации). У меня есть следующий фрагмент кода, касающегося componentsSeparatedByString
:
TBQuadTreeNodeData TBDataFromLine(NSString *line)
{
NSString *[email protected]">>>>>>>>";
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 *[email protected]">>>>>>>>";
for(NSMutableDictionary *dic in marr)
{
NSString *newStr=[NSString stringWithFormat:@"%@%@",[dic[@"latitude"] isEqualToString:@""][email protected]" ":dic[@"latitude"],separatestuff];
newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"longitude"] isEqualToString:@""][email protected]" ":dic[@"longitude"],separatestuff];
newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"id"] isEqualToString:@""][email protected]" ":dic[@"id"],separatestuff];
newStr=[NSString stringWithFormat:@"%@%@",newStr,[dic[@"image"] isEqualToString:@""][email protected]" ":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 *[email protected]">>>>>>>>";
for(NSMutableDictionary *dic in marr)
{
NSString *newStr=[NSString stringWithFormat:@"%@%@",[dic[@"lat"] isEqualToString:@""][email protected]" ":dic[@"lat"],separatestuff2];
newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"lang"] isEqualToString:@""][email protected]" ":dic[@"lang"],separatestuff2];
newStr=[NSString stringWithFormat:@"%@%@%@",newStr,[dic[@"id"] isEqualToString:@""][email protected]" ":dic[@"id"],separatestuff2];
newStr=[NSString stringWithFormat:@"%@%@",newStr,[dic[@"image"] isEqualToString:@""][email protected]" ":dic[@"image"]];
[newMarr addObject:newStr];
}
//NSLog(@"NEW Array: %@",newMarr);
[self.coordinateQuadTree buildTree:newMarr];
}
}
UPDATE: Это блок кода, где 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);
}
}
Я работаю над этой проблемой часами и до сих пор не знаю.
UPDATE: Вот лог отладчика я получаю
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
Кажется, что метод, вызывающий 'TBDataFromLine', передается в словаре вместо строки. –
Где вы называете метод «TBDataFromLine» - укажите код –
TBDataFromLine (строка NSString *) <--- проверьте все места, где вы вызываете эту функцию. Вы определенно проходите неправильный параметр dude. –