iOS NSDictionary内存压力崩溃

时间:2014-04-03 17:19:10

标签: ios objective-c uitableview nsarray nsdictionary

我有一个非常大的模型NSDictionary,其中我存储了400个公司信息,然后在初始加载期间创建NSArrays以在App中用于速度。当我有大约100家公司时,它只是运行缓慢,而不是因为内存压力导致我的应用程序崩溃。关于如何以更有效的方式构建这个问题的任何建议?

 - (NSArray*)exhibitorDetail{
NSDictionary *company1 = @{@"id": @"id1", @"name": @"company xyz", @"details": @"Booth: 1700", @"png": @"exhibitor_map1700.png"};
NSDictionary *company2 = @{@"id": @"id2", @"name": @"company abc", @"details": @"Booth: 1721", @"png": @"exhibitor_map1721.png"};
NSDictionary *company3 = @{@"id": @"id3", @"name": @"company mno", @"details": @"Booth: 805", @"png": @"exhibitor_map805.png"};
NSDictionary *company4 = @{@"id": @"id4", @"name": @"company efg", @"details": @"Booth: 1320, 1321", @"png": @"exhibitor_map1320.png"};
...through 400 dictionaries of companies.

 NSMutableArray *allCompanies = [NSMutableArray arrayWithObjects:company1, company2, company3, company4,..]l

NSSortDescriptor *nameDescripter = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending: YES selector:@selector(caseInsensitiveCompare:)];

NSArray *descriptors = @[nameDescripter];

[allCompanies sortUsingDescriptors:descriptors];

return allCompanies;
}

然后将Dictionary用于UITableView

- (NSDictionary*) countPerLetter {

NSDictionary *dictionary;
NSMutableArray *objects = [[NSMutableArray alloc] init];

NSArray *letters = self.exhibitorFirstLetter;
NSArray *names = self.exhibitorName;

for (NSInteger i = 0; i < [self.exhibitorFirstLetter count]; i++)
{
    [objects addObject:[[NSMutableArray alloc] init]];
}

dictionary = [[NSDictionary alloc] initWithObjects: objects forKeys:letters];

for (NSString *name in names) {   //zen software, zeb, bakken
    NSString *firstLetter = [name substringToIndex:1];  //z, b

    for (NSString *letter in letters) {  //z, b
        if ([firstLetter isEqualToString:letter]) {
            NSMutableArray *currentObjects = [dictionary objectForKey:letter];
            [currentObjects addObject:name];
        }
    }

}

return dictionary;
}

这是我的初始设置数组,它主要提取公司&#34; name&#34;和公司&#34;详细信息&#34;进入单个阵列以方便使用。运行它会调用上面的方法,从而调用崩溃。

 -(void) setupViewArrays {
ExhibitorData *ed = [[ExhibitorData alloc]init];
NSArray *exhibitorKeys = [ed.countPerLetter allKeys];
NSDictionary *exhibitorDictionary = [ed countPerLetter];

NSArray *exhibitorSetupArrays = @[exhibitorKeys, exhibitorDictionary];
}

0 个答案:

没有答案