我有兩種模式 - 模式1和模式2可以通過中央按鈕進行切換。模式之間的切換允許用戶查看兩種不同類型的聚類註釋。NSCFDictionary - 無法識別的選擇器發送到實例
我能夠切換模式1模式2輕鬆,但是當我切換回模式1我得到這個討厭的錯誤
-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fb1308cca50
我打開我的代碼,並在TBClusteredAnnotations.m
(劇本我用於集羣化)。我有與下面的代碼片斷,以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 *separatestuff2[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);
}
}
我一直在這個問題上幾個小時,現在,仍然沒有任何線索。
更新:這是調試器的日誌中我得到
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 * line)<---檢查你調用這個函數的所有地方。你肯定會傳錯一個錯誤的參數。 –