0

NSArrayの内部をPFObjectソートする必要があります。PFObjectには、曜日を含む配列を含む複数のアイテムが含まれており、PFObject 内の各アイテムで最も頻繁に繰り返される日付を知る必要があります。私の内部cellForRowAtIndexPath(TableViewの各アイテムについて知る必要があるため、これがあります:

NSArray *yourArrayhere = object[@"DatesSuggested"];

    if (yourArrayhere == NULL) {
        //cell.text = @"No votes have been cast for this activity yet.";


    }
    else {
        NSCountedSet *setOfObjects = [[NSCountedSet alloc] initWithArray:yourArrayhere];

        //Declaration of objects
        NSString *mostOccurringObject = @"";
        NSUInteger highestCount = 0;

        //Iterate in set to find highest count for a object
        for (NSString *strObject in setOfObjects)
        {
            NSUInteger tempCount = [setOfObjects countForObject:strObject];

                highestCount = tempCount;
                mostOccurringObject = strObject;
                NSLog(@"MOSTO%@", mostOccurringObject);
            NSLog(@"MOSTC%lu", (unsigned long)highestCount);

        }
        NSString *allcombined = [[[[[[[@"Currently there are " stringByAppendingString:votesFor] stringByAppendingString:@" votes for and "] stringByAppendingString:votesAgainst] stringByAppendingString:@" votes against "] stringByAppendingString:object[@"Title"]] stringByAppendingString:@", with the most suggested date being "] stringByAppendingString:mostOccurringObject];
        cell.detailTextLabel.text = allcombined;
        NSString *toSave = [mostOccurringObject stringByAppendingString:[NSString stringWithFormat:@" %lu", (unsigned long)highestCount]];
        NSLog(@"Highest %@", toSave);
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:toSave forKey:cell.textLabel.text];
        [defaults synchronize];
    }

これは時々機能します。配列の 1 つが含ま(Monday, Monday, Monday, Thursday)れており、月曜日が最も人気があり、3 票を得ていることを示しています。別の配列も同じですが、木曜日が最も人気があることを示しています。なぜこのように振る舞うのか、私は困惑しています。

4

0 に答える 0