不知道什么原因,自己在做删除操作的时候,会有个错误,总是删除了,又以空的形式出现,我火了。
查找了很多资料,自己拼出一个还算能够使用的方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| -(void) refreshData { NSMutableDictionary *tmpMutableDictionary = [NSMutableDictionary dictionaryWithCapacity:20]; NSArray *allKeys = [self.dataDic allKeys]; NSMutableArray *allMutableKeys = [allKeys mutableCopy]; NSComparator cmptr = ^(id obj1, id obj2){ if ([obj1 integerValue] > [obj2 integerValue]) { return (NSComparisonResult)NSOrderedDescending; } if ([obj1 integerValue] < [obj2 integerValue]) { return (NSComparisonResult)NSOrderedAscending; } return (NSComparisonResult)NSOrderedSame; }; NSArray *resultKeys = [allMutableKeys sortedArrayUsingComparator:cmptr]; int k = 0; for (id item in resultKeys) { NSDictionary *dic = [self.dataDic valueForKey:[NSString stringWithFormat:@"%@",item]]; [tmpMutableDictionary setValue:dic forKey:[NSString stringWithFormat: @"%d", k]]; k++; }
self.dataDic = [tmpMutableDictionary mutableCopy]; }
|