UITableView删除时,刷新table的方法

不知道什么原因,自己在做删除操作的时候,会有个错误,总是删除了,又以空的形式出现,我火了。

查找了很多资料,自己拼出一个还算能够使用的方法

-(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];
}

comments powered by Disqus