Вот код.
self.names = [[NSMutableDictionary alloc] init];
NSMutableDictionary *mainDict = [[NSMutableDictionary alloc] init];
NSMutableArray *subArray = [[NSMutableArray alloc] init];
NSMutableArray *arrayOfKeys = [[NSMutableArray alloc] init];
NSMutableDictionary *bufDict = [[NSMutableDictionary alloc] init];
NSString *bufStr;
NSString *newKeyStr;
NSString *oldKeyStr;
oldKeyStr = @"";
newKeyStr = oldKeyStr;
NSLog(@"start making NEW format");
for (int i=0; i < [temp count]; i++)
{
//if (!(bufDict == nil)) [bufDict removeAllObjects];
bufDict = [temp objectAtIndex:i];
bufStr = [bufDict objectForKey:kNameKey];
if ([bufStr length]>=2)
{
if ([newKeyStr isEqualToString:oldKeyStr])
{
}
else
[arrayOfKeys addObject:newKeyStr];
oldKeyStr = newKeyStr;
}
}
int x=0;
for (int i = 0; i< [arrayOfKeys count];i++)
{
newKeyStr = [arrayOfKeys objectAtIndex:i];
for (int j=x; j< [temp count]; j++)
{
bufDict = [temp objectAtIndex:j];
bufStr = [bufDict objectForKey:kNameKey];
if ([bufStr length] >=2)
{
oldKeyStr = [bufStr substringToIndex:1];
if ([oldKeyStr isEqualToString:newKeyStr])
{
[subArray addObject:bufDict];
}
else
{
NSLog(@"newKEyStr setting to mainDict is %@",newKeyStr);
[mainDict setObject:subArray forKey:newKeyStr];
[self.names setObject:subArray forKey:newKeyStr];
NSArray *arr= [self.names objectForKey:newKeyStr];
NSLog(@"array count: %i",[arr count]);
[subArray removeAllObjects];
x=j;
break;
}
}
}
}
NSLog(@"end of making format dict!!!");
[mainDict release];
self.keys = arrayOfKeys;
[arrayOfKeys release];
[subArray release];
[bufDict release];
for (int v = 0 ; v< [keys count];v++)
{
NSString *str = [keys objectAtIndex:v];
NSLog(@"str = %@",str);
NSArray *arr = [self.names objectForKey:str];
NSLog(@"arr= %i",[arr count]);
}
Так что мой лог
start making NEW format
newKEyStr setting to mainDict is 1
array count: 1
newKEyStr setting to mainDict is 2
array count: 22
newKEyStr setting to mainDict is 3
array count: 2
newKEyStr setting to mainDict is A
array count: 12
newKEyStr setting to mainDict is B
array count: 16
newKEyStr setting to mainDict is C
array count: 33
newKEyStr setting to mainDict is D
array count: 6
newKEyStr setting to mainDict is E
array count: 9
newKEyStr setting to mainDict is F
array count: 6
newKEyStr setting to mainDict is G
array count: 5
newKEyStr setting to mainDict is H
array count: 17
newKEyStr setting to mainDict is I
array count: 3
end of making format dict!!!
str = 1
arr= 1
str = 2
arr= 1
str = 3
arr= 1
str = A
arr= 1
str = B
arr= 1
str = C
arr= 1
str = D
arr= 1
str = E
arr= 1
str = F
arr= 1
str = G
arr= 1
str = H
arr= 1
str = I
arr= 1
Как вы можете видеть, похоже, у меня есть nsdictionary self.names с массивами и есть некоторые nsdictionaries в nsarrays, НО в конце, когда я хочу проверить LOG, говорится, что в nsarray есть только 1 объект. Кто-нибудь может мне помочь?
Извините за длинный вопрос, но я не могу решить проблему в течение нескольких часов. СПАСИБО