3

辞書データの配列内に辞書の配列があります。ユーザーの選択に基づいて辞書の配列内をソートする必要があります。

たとえば、私のデータ値は

sortResultArray--(
        {
        alertSeverity = 1;
        customerName = TPMG;
        endDate = "05-05-2013";
        isProjectHide = 1;
        kpiData =         (
                        {
                kpiActual = 18;
                kpiName = Issue;
                kpiPlanned = "";
                kpiUnit = "";
            },
                        {
                kpiActual = 7;
                kpiName = Progress;
                kpiPlanned = "";
                kpiUnit = "%";
            },
                            );
        lastInvoiceDate = "05-04-2013";
        nextBillingDate = "05-04-2013";
        nextMilestoneDate = "10-04-2013";
        nextReviewDate = "08-04-2013";
        plannedCompletionDate = "04-05-2013";
        projectID = 3000;
        projectName = "Rain Harvesting";
        projectSortType = "";
        projectStatus = 1;
        startDate = "01-01-2013";
    },
        {
        alertSeverity = 2;
        customerName = Florida;
        endDate = "12-12-2014";
        isProjectHide = 1;
        kpiData =         (
                                {
                kpiActual = 20;
                kpiName = Issue;
                kpiPlanned = "";
                kpiUnit = "";
            },
                        {
                kpiActual = 10;
                kpiName = Progress;
                kpiPlanned = "";
                kpiUnit = "%";
            },
                         );
        lastInvoiceDate = "12-05-2012";
        nextBillingDate = "12-05-2013";
        nextMilestoneDate = "16-05-2012";
        nextReviewDate = "12-05-2012";
        plannedCompletionDate = "12-08-2014";
        projectID = 4000;
        projectName = "Bridge Planning";
        projectSortType = "";
        projectStatus = 1;
        startDate = "12-12-2011";
    },
        {
        alertSeverity = 3;
        customerName = BIRO;
        endDate = "01-01-2013";
        isProjectHide = 1;
        kpiData =         (
                        {
                kpiActual = 16;
                kpiName = Issue;
                kpiPlanned = "";
                kpiUnit = "";
            },
                        {
                kpiActual = 5;
                kpiName = Progress;
                kpiPlanned = "";
                kpiUnit = "%";
            },
                           );
        lastInvoiceDate = "20-12-2013";
        nextBillingDate = "13-12-2013";
        nextMilestoneDate = "28-12-2013";
        nextReviewDate = "25-12-2013";
        plannedCompletionDate = "30-12-2013";
        projectID = 1000;
        projectName = "Rocket Launching";
        projectSortType = "";
        projectStatus = 1;
        startDate = "11-11-2012";
    },

ここで、ユーザーが問題または進行状況キー (kpiName = 問題、kpiName = 進行状況) を選択したとします。kpiActual 値に基づいて並べ替える必要があります (kpiActual = 5)。

つまり、ユーザーが問題を選択すると、並べ替えの結果は次のようになります

                kpiActual = 20;
                kpiName = Issue;
and then      
                kpiActual = 18;
                kpiName = Issue;

これが私が試したソースコードです

sortResultArray = [[NSMutableArray alloc] init];
    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    [tempArray removeAllObjects];
    [tempArray addObjectsFromArray:listOfProjects];

        NSString *key = @"kpiName";
        NSSortDescriptor *statusDescriptor = [[NSSortDescriptor alloc] initWithKey:key ascending:NO];
        NSSortDescriptor *kpiDescriptor = [[NSSortDescriptor alloc] initWithKey:@"kpiActual" ascending:NO];
        NSArray *sortDescriptors = [NSArray arrayWithObjects:statusDescriptor,kpiDescriptor,nil];
        NSArray *sortedArray = [tempArray sortedArrayUsingDescriptors:sortDescriptors];
        [statusDescriptor release];
        [tempArray removeAllObjects];
        tempArray = (NSMutableArray*)sortedArray;
        [sortResultArray removeAllObjects];
        [sortResultArray addObjectsFromArray:tempArray];
4

0 に答える 0