从UICollectionView中的Plist排序NSMutableDictionnary

时间:2014-05-13 15:01:19

标签: ios objective-c sorting nsmutabledictionary

我有一个uicollectionView,它显示字典中的项目(包含在plist中的主字典中)。我需要用键" order"来对它进行排序。这是在我的词典里面。我无法想象如何做到这一点。我尝试使用描述符比较键而没有成功。

我从nsmutablearrays中取值,在单元格中显示它们。

这里是我的代码(工作未分类的代码):

//To retreive the data from the plist
NSMutableDictionary *items = [[NSMutableDictionary alloc] initWithContentsOfFile: finalPath];

//initialize arrays

_order = [[NSMutableArray alloc]initWithCapacity:10];
_name = [[NSMutableArray alloc]initWithCapacity:10];
_role = [[NSMutableArray alloc]initWithCapacity:10];
_image = [[NSMutableArray alloc]initWithCapacity:10];
_description = [[NSMutableArray alloc]initWithCapacity:10];
_email = [[NSMutableArray alloc]initWithCapacity:10];
_googleplus = [[NSMutableArray alloc]initWithCapacity:10];

//load every NSDictionnary on the view

NSMutableDictionary *loadedItem = [[NSMutableDictionary alloc]initWithCapacity:1];
NSMutableDictionary *theMember = [[NSMutableDictionary alloc]initWithCapacity:10];

loadedItem = [items objectForKey:@"Team"];

for (int i = 0; i < loadedItem.count; i++) {

    theMember = loadedItem.allValues[i];

    NSString *memberOrder = [theMember objectForKey:@"order"];
    [_order addObject:memberOrder];
    NSLog(@"member order = %@", _order);

    NSString *memberName = [theMember objectForKey:@"name"];
    [_name addObject:memberName];
    NSLog(@"member name = %@", _name);

    NSString *memberRole = [theMember objectForKey:@"role"];
    [_role addObject:memberRole];
    NSLog(@"member role = %@", _role);

    NSString *memberImage = [theMember objectForKey:@"image"];
    [_image addObject:memberImage];
    NSLog(@"member image = %@", _image);

    NSString *memberDesc = [theMember objectForKey:@"description"];
    [_description addObject:memberDesc];
    NSLog(@"member description = %@", _description);

    NSString *memberMail = [theMember objectForKey:@"email"];
    [_email addObject:memberMail];
    NSLog(@"member mail = %@", _email);

    NSString *memberGoogleplus = [theMember objectForKey:@"googleplus"];
    [_googleplus addObject:memberGoogleplus];
    NSLog(@"member googleplus = %@", _googleplus);
    }
    [self.collectionView reloadData];

}

1 个答案:

答案 0 :(得分:0)

我通过将我的mai ndict更改为一个更好操作的数组来解决这个问题。