iOS - 如何从NSMutableArray获取字符串的第一个字符并将其存储在NSMutableDictionary中?

时间:2015-09-22 07:39:07

标签: ios objective-c nsmutablearray nsdictionary

- (void)loadData: (NSMutableArray *)myMutableArray  {

    self.myMutableDict = [[NSMutableDictionary alloc] init];

    for (NSString *str in myMutableArray) {

        NSString *key = [str substringToIndex:1];

        NSLog(@"Key: %@", key);

        NSLog(@"str: %@", str);

        if ([self.myMutableDict objectForKey:key]) {

            NSMutableArray *list = (NSMutableArray *)[self.myMutableDict objectForKey:key];

            [list addObject:str];

            [self.myMutableDict setObject:list forKey:key];

        } else {

            NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:str, nil];

            [self.myMutableDict setObject:list forKey:key];
        }

    }

    [self.tblAlphabeticalOrder reloadData];

}

0 个答案:

没有答案