iOS错误,我无法复制

时间:2015-01-10 15:09:36

标签: ios objective-c

我在App Store中有一个修订测验应用程序,过去3个月每天都有大约10次下载。它使用得很好,而且大部分都有很好的评论。然而,最近我有两个一星评价,因为人们抱怨测验结束后“评论”屏幕是空白的。

我在iPhone 5 / 5c / 5s上尝试过这种方法,效果非常好。这些是我可以访问的唯一设备,但我也运行了iPad和iPhone 6版本的模拟器,我无法复制问题。

流程是RootController-> QuizController-> ResultsController-> ReviewController。测验控制器有一个名为GameManager的对象作为实例变量。这将在测验进行时跟踪用户的答案和问题,并在测验期间从测验传递到结果,然后传递到评论部分。

传递对象的函数是:

//From Quiz to Results 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"quiz2results"])
{
    // Get reference to the destination view controller
    ResultsController *vc = [segue destinationViewController];

    // Pass any objects to the view controller here, like...
    [vc setManager:_manager];
}
}

//From Results to Review
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"results2review"])
{
    // Get reference to the destination view controller
    ReviewController *vc = [segue destinationViewController];

    // Pass any objects to the view controller here, like...
    [vc setManager:_manager];
}
}

然后在Review控制器中执行以下代码:

-(void)setReviewText{

NSArray* questions = [[NSArray alloc] init];
questions = [_manager getAllQuestions];
NSMutableArray* userAnswer = [[NSMutableArray alloc] init];
userAnswer = [self answersAttributed];

if (userAnswer == nil)
{
    _output.text = @"Error";
}

NSMutableAttributedString *mutableAttString = [[NSMutableAttributedString alloc] init];

int i = 0;
NSAttributedString *linebreak =[[NSAttributedString alloc] initWithString:@"\n"];
for (Question* q in questions)
{
    if (i == [userAnswer count])
        break;

    NSAttributedString *qtext =[[NSAttributedString alloc] initWithString:q.questionText];
    NSAttributedString *ctext =[[NSAttributedString alloc] initWithString:@"Correct Answer:\n"];

    NSAttributedString *atext =[[NSAttributedString alloc] initWithString:q.answerText];
    NSAttributedString *ytext =[[NSAttributedString alloc] initWithString:@"Your Answer:\n"];
    NSAttributedString *utext =[[NSAttributedString alloc] initWithAttributedString:userAnswer[i]];
    [mutableAttString appendAttributedString:qtext];
    [mutableAttString appendAttributedString:linebreak];
    [mutableAttString appendAttributedString:ctext];
    [mutableAttString appendAttributedString:atext];
    [mutableAttString appendAttributedString:linebreak];
    [mutableAttString appendAttributedString:ytext];
    [mutableAttString appendAttributedString:utext];
    [mutableAttString appendAttributedString:linebreak];
    [mutableAttString appendAttributedString:linebreak];
    i++;
}
NSAttributedString* outText = [[NSAttributedString alloc] init];
outText = [mutableAttString mutableCopy];
_output.attributedText = outText;
[_output setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]];
}

-(NSMutableArray*)answersAttributed
{
NSMutableArray* ansAtt = [[NSMutableArray alloc] init];
NSArray* questions = [[NSArray alloc] init];
questions = [_manager getAllQuestions];

NSArray* userAnswers = [[NSArray alloc] init];
userAnswers = [_manager getAllUserAnswers];


if ([questions count] != [userAnswers count])
{
    return ansAtt;
}


int i = 0;
for (NSString* userAnswer in userAnswers )
{
    if([[questions[i] answerText] isEqualToString:userAnswer] )
    {
        NSDictionary *attributes = @{NSBackgroundColorAttributeName:[UIColor greenColor]};
        NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:userAnswer attributes:attributes];
        [ansAtt addObject:attrString];
    }
    else
    {
        NSDictionary *attributes = @{NSBackgroundColorAttributeName:[UIColor redColor]};
        NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:userAnswer attributes:attributes];
        [ansAtt addObject:attrString];

    }
    i++;
}

return ansAtt;
}

如果有人能对此有所了解,我会很高兴。到目前为止,我已经提到了这个问题的原因。

0 个答案:

没有答案