0

ディクショナリ値の配列があり、個々の配列項目に対してカウンター メソッドを実装しましたが、最終的なカウンター値の取得に問題がありました。個々のカウンター値を追加していました。

ここにソースコードがあります。

-(void)getData
{
    [lReportArr removeAllObjects];
    lMetaCount = 0;
    NSMutableArray *lTempArr = [[NSMutableArray alloc] initWithArray:lMetaArray];
    NSLog(@"Metabolic Array:-%@", lTempArr);
    for (int i = 0; i < [lTempArr count]; i++)
    {
        NSMutableDictionary *lDict = [lTempArr objectAtIndex:i];

        NSString *lTitle = [lDict objectForKey:@"title"];
        //Glucose Low count
        if ([lTitle rangeOfString:@"Glucose reading : Low"].length > 0) 
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"Low BG:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        //Glucose High count
        else if ([lTitle rangeOfString:@"Glucose reading : High"].length > 0) 
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"High BG:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        //Wrong Dose Cause count
        else if([lTitle rangeOfString:@"Low Cause: Wrong Dose"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"LG Wrong Dose:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        else if([lTitle rangeOfString:@"High Cause: Wrong Dose"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"HG Wrong Dose:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        //Symptoms Cause count
        else if([lTitle rangeOfString:@"Low Cause: Illness"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"LG Illness:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        else if([lTitle rangeOfString:@"High Cause: Illness"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"HG Symptoms:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        //LG n HG Treatment count
        else if([lTitle rangeOfString:@"Treatment: Emergency Room"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"Emergency Room:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        else if([lTitle rangeOfString:@"Treatment: Hospitalization"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"Hospitalization:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        else if([lTitle rangeOfString:@"Treatment: Extra MD Office"].length > 0)
        {
            lMetaCount++;
            NSString *lCount = [NSString stringWithFormat:@"Extra MD Office:%d",lMetaCount];
            [lDict setValue:lCount forKey:@"metabolicCount"];
        }
        [lReportArr addObject:lDict];
    }
}
4

1 に答える 1

0

あなたが使用することができます

int c = [[lReportArr objectAtIndex:0] valueForKey:@"metabolicCount"];

これにより、metabolicCount キーが含まれている場合、辞書に格納されている最初のオブジェクトの metabolicCount 値の最終カウントが得られます

于 2012-04-25T07:05:49.410 に答える