从PFQuery设置整数值

时间:2015-12-05 21:15:18

标签: objective-c parse-platform

我无法从pfquery获取整数值。

这是我想要解决的全部代码

-(void)GetTotalVotes{

PFQuery *querya = [PFQuery queryWithClassName:@"AnswerStorage"];
[querya whereKey:@"Quiz" equalTo: [NSString stringWithFormat:@"%i",CategoryLoaded]];
[querya whereKey:@"Question" equalTo: [NSString stringWithFormat:@"%i",QuestionSelected]];
[querya whereKey:@"Answer" equalTo: [NSString stringWithFormat:@"a"]];
[querya getFirstObjectInBackgroundWithBlock:^(PFObject *atotal, NSError *error){
    if (!error){

        NSUInteger answerATotal = [atotal[@"Total"]intValue];

        VoteBScore = answerATotal;

        [atotal saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (succeeded == YES){
            }
            else{}
        }];
    }
    else{
    }}];

PFQuery *queryb = [PFQuery queryWithClassName:@"AnswerStorage"];
[queryb whereKey:@"Quiz" equalTo: [NSString stringWithFormat:@"%i",CategoryLoaded]];
[queryb whereKey:@"Question" equalTo: [NSString stringWithFormat:@"%i",QuestionSelected]];
[queryb whereKey:@"Answer" equalTo: [NSString stringWithFormat:@"b"]];
[queryb getFirstObjectInBackgroundWithBlock:^(PFObject *btotal, NSError *error){
    if (!error){

        NSUInteger answerBTotal = [btotal[@"Total"]intValue];

        VoteBScore = answerBTotal;


        [btotal saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (succeeded == YES){
            }
            else{}
        }];
    }
    else{
    }}];

PFQuery *queryc = [PFQuery queryWithClassName:@"AnswerStorage"];
[queryc whereKey:@"Quiz" equalTo: [NSString stringWithFormat:@"%i",CategoryLoaded]];
[queryc whereKey:@"Question" equalTo: [NSString stringWithFormat:@"%i",QuestionSelected]];
[queryc whereKey:@"Answer" equalTo: [NSString stringWithFormat:@"c"]];
[queryc getFirstObjectInBackgroundWithBlock:^(PFObject *ctotal, NSError *error){
    if (!error){

        NSUInteger answerCTotal = [ctotal[@"Total"]intValue];

        VoteBScore = answerCTotal;

        [ctotal saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (succeeded == YES){
            }
            else{}
        }];
    }
    else{
    }}];

PFQuery *queryd = [PFQuery queryWithClassName:@"AnswerStorage"];
[queryd whereKey:@"Quiz" equalTo: [NSString stringWithFormat:@"%i",CategoryLoaded]];
[queryd whereKey:@"Question" equalTo: [NSString stringWithFormat:@"%i",QuestionSelected]];
[queryd whereKey:@"Answer" equalTo: [NSString stringWithFormat:@"c"]];
[queryd getFirstObjectInBackgroundWithBlock:^(PFObject *dtotal, NSError *error){
    if (!error){

        NSUInteger answerDTotal = [dtotal[@"Total"]intValue];

        VoteDScore = answerDTotal;

        AllVoteScore = VoteAScore + VoteBScore + VoteCScore + VoteDScore;

        [dtotal saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (succeeded == YES){
            }
            else{}
        }];}

    else{
    }}];




}

-(IBAction)Answer1:(id)sender{

NSString *quizString = [NSString stringWithFormat:@"%i",CategoryLoaded];
NSString *questionString = [NSString stringWithFormat:@"%i",QuestionSelected];
NSString *answerString = [NSString stringWithFormat:@"a"];

PFObject *newAnswerVote = [PFObject objectWithClassName:@"QuizData"];
newAnswerVote[@"quiz"] = quizString;
newAnswerVote[@"question"] = questionString;
newAnswerVote[@"answer"] = answerString;

[newAnswerVote saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (succeeded == YES){

        PFQuery *queryb = [PFQuery queryWithClassName:@"AnswerStorage"];
        [queryb whereKey:@"Quiz" equalTo: [NSString stringWithFormat:@"%i",CategoryLoaded]];
        [queryb whereKey:@"Question" equalTo: [NSString stringWithFormat:@"%i",QuestionSelected]];
        [queryb whereKey:@"Answer" equalTo: [NSString stringWithFormat:@"a"]];
        [queryb getFirstObjectInBackgroundWithBlock:^(PFObject *total, NSError *error){
            [total incrementKey:@"Total"];


            [total saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (succeeded == YES){
    }
                else{}}];}
         ];}}];

[self GetTotalVotes];

if (VoteAScore > VoteBScore || VoteAScore > VoteCScore || VoteAScore > VoteDScore || VoteBScore > VoteCScore || VoteBScore > VoteDScore){

    Outcome = 0;
}

else if (VoteAScore > VoteBScore || VoteAScore > VoteCScore || VoteAScore > VoteDScore || VoteCScore > VoteBScore || VoteCScore > VoteDScore){

    Outcome = 1;

}

else if (VoteAScore > VoteBScore || VoteAScore > VoteCScore || VoteAScore > VoteDScore || VoteDScore > VoteBScore || VoteDScore > VoteCScore){

    Outcome = 2;


}

else if (VoteBScore > VoteAScore || VoteBScore > VoteCScore || VoteBScore > VoteDScore){

    Outcome = 3;

}

else if (VoteCScore > VoteAScore || VoteCScore > VoteBScore || VoteCScore > VoteDScore){

    Outcome = 4;

}

else if (VoteDScore > VoteAScore || VoteDScore > VoteBScore || VoteDScore > VoteCScore){

    Outcome = 5;

}
switch (Outcome)
{
    case 0:

    OneFraction = VoteAScore/AllVoteScore;
    TwoFraction = VoteBScore/AllVoteScore;
    Margin = OneFraction - TwoFraction;
    InvertedMargin = 1 - Margin;

    AddScore = Margin * 1000;

    ScoreNumber = ScoreNumber + AddScore;

    [self RightAnswer];

        break;

    case 1:

        OneFraction = VoteAScore/AllVoteScore;
        TwoFraction = VoteCScore/AllVoteScore;
        Margin = OneFraction - TwoFraction;
        InvertedMargin = 1 - Margin;

        AddScore = Margin * 1000;

        ScoreNumber = ScoreNumber + AddScore;


    [self RightAnswer];

        break;


    case 2:

        OneFraction = VoteAScore/AllVoteScore;
        TwoFraction = VoteDScore/AllVoteScore;
        Margin = OneFraction - TwoFraction;
        InvertedMargin = 1 - Margin;

        AddScore = Margin * 1000;

    ScoreNumber = ScoreNumber + AddScore;

    [self RightAnswer];

        break;

    case 3:

        OneFraction = VoteBScore/AllVoteScore;
        TwoFraction = VoteAScore/AllVoteScore;
        Margin = OneFraction - TwoFraction;
        InvertedMargin = 1 - Margin;

        AddScore = Margin * 1000;

    ScoreNumber = ScoreNumber - AddScore;

    [self WrongAnswer];

        break;

    case 4:

        OneFraction = VoteCScore/AllVoteScore;
        TwoFraction = VoteAScore/AllVoteScore;
        Margin = OneFraction - TwoFraction;
        InvertedMargin = 1 - Margin;

        AddScore = Margin * 1000;

    ScoreNumber = ScoreNumber - AddScore;

    [self WrongAnswer];

        break;

    case 5:

        OneFraction = VoteDScore/AllVoteScore;
        TwoFraction = VoteAScore/AllVoteScore;
        Margin = OneFraction - TwoFraction;
        InvertedMargin = 1 - Margin;

        AddScore = Margin * 1000;

    ScoreNumber = ScoreNumber - AddScore;

    [self WrongAnswer];

        break;

}}

然而,它始终将我的查询中的整数值返回为0,尽管" Total"柱。谁知道我在这里做错了什么?

0 个答案:

没有答案