I am trying to update the text of a UITextView programmatically. This was working a couple of days ago, but can’t tell why it has stopped.
Creating the UITextView
self.recordInfoTextView = [[UITextView alloc] initWithFrame:textFrame];
self.recordInfoTextView.editable=NO;
self.recordInfoTextView.scrollEnabled=NO;
self.recordInfoTextView.multipleTouchEnabled=NO;
self.recordInfoTextView.userInteractionEnabled=NO;
self.recordInfoTextView.textAlignment=UITextAlignmentCenter;
self.recordInfoTextView.font=[UIFont systemFontOfSize:12.0f];
self.recordInfoTextView.text=@"Record 1 of 1";
[self.recordInfoTextView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleTopMargin)];
[self.view addSubview:recordInfoTextView];
The UITextView appears with the initial string value. However, it does not update here:
-(void)displayContentInTextView {
self.recordInfoTextView.text=[NSString stringWithFormat:@"Record %d of %d", currentIndex+1, [idNumberArray count]];
NSLog(@"displayContentInWebView: Record %d of %d", currentIndex+1, [idNumberArray count]);
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
if (currentIndex < ([idNumberArray count]-1)) {
currentIndex++;
recordID = [[idNumberArray objectAtIndex:currentIndex] intValue];
[self displayContentInTextView];
}
} else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
if (currentIndex > 0) {
currentIndex--;
recordID = [[idNumberArray objectAtIndex:currentIndex] intValue];
[self displayContentInTextView];
}
}
}
The log shows that displayContentInWebView is called appropriately and the expected information is sent to the log, however, the UITextView does not update, but continues to display the initial text.
Thanks in advance! Tim
it seems the question is already answered but:
you can replace all
self.recordInfoTextViewwith justrecordInfoTextViewit should still work and hey, less code 🙂