我有一个模板测验应用程序已经在应用程序商店中以各种形式存在了一段时间,通常它收到良好的评论并且没有错误报告。
最近我有两个错误报告,人们使用带有iOS 8.1.2或8.1.3的iPad,并说现在我用来显示问题的UITextView是空白的。
我无法复制这个错误,但如果有人能够对此有所了解,我将不胜感激。
对象questions
和userAnswer
不是nil,因此肯定是UITextView问题。
控制器在这里:
@interface ReviewController () @property (strong, nonatomic) IBOutlet UITextView *output; @end @implementation ReviewController - (void)viewDidLoad { [super viewDidLoad]; [self setReviewText]; // Do any additional setup after loading the view. } -(void)setReviewText{ NSArray* questions = [[NSArray alloc] init]; questions = [_manager getAllQuestions]; NSMutableArray* userAnswer = [[NSMutableArray alloc] init]; userAnswer = [self answersAttributed]; if(questions == nil) _output.text = @"Questions Error"; 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; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Make sure your segue name in storyboard is the same as this line if ([[segue identifier] isEqualToString:@"review2results"]) { // Get reference to the destination view controller ReviewController *vc = [segue destinationViewController]; // Pass any objects to the view controller here, like... [vc setManager:_manager]; } }
答案 0 :(得分:0)
使用自动布局时,如果您没有足够的限制来完全指定大小和位置,那么有时您会看到并且有时您会赢。未指定的约束可以具有随机值,例如0高度或屏幕外位置。
检查以确保完全指定约束。
答案 1 :(得分:0)
在我的案例中,textview
标记为Non-Editable
,{strong> Non-Selectable
中的Storyboard
在 {{1}上有相同的奇怪行为} (iOS 9 +中没有问题)。
iOS 8.1
修正了这个问题:
- (void)viewDidLoad {
[super viewDidLoad];
textview.attributedText = [[NSAttributedString alloc] initWithString:@"non-nil"]];
value = textview.attributedText;
//^ value is nil !!!
}