我的NSMutableDictionary删除对象当我删除IOS中的NSMutableArray?
问题描述:
contactSectionDict = [[NSMutableDictionary alloc] init];
contactsForSection = [[NSMutableArray alloc] init];
contactsIndexTitles = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H",@"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z",@"#"];
for(int i=0;i<contactsIndexTitles.count;i++)
{
for(int j=0;j<names.count;j++)
{
NSArray * splitArray = [[names objectAtIndex:j] componentsSeparatedByString:@" "];
if ([[splitArray objectAtIndex:0] hasPrefix:[contactsIndexTitles objectAtIndex:i]]) {
//[contactSectionDict setValue:[names objectAtIndex:j] forKey:[contactsIndexTitles objectAtIndex:i]];
[contactsForSection addObject:[names objectAtIndex:j]];
}
}
[contactSectionDict setValue:contactsForSection forKey:[contactsIndexTitles objectAtIndex:i]];
[contactsForSection removeAllObjects];
}
在第一次迭代中,它存储contactsForSection中的36个对象,并将其存储在contactsectionDict中,用于键“A”,然后我想存储索引B的联系人,为此我从contactsForSection中删除对象,但它也删除了值字典中的关键字“A”。 当字典将设置对所有索引,然后我会给它的表视图显示他们像苹果联系应用程序。 请建议我更好的方法。我的NSMutableDictionary删除对象当我删除IOS中的NSMutableArray?
答
您需要创建一个新的contactsForSection
阵列的每个字母: