Note that there are some explanatory texts on larger screens.

plurals
  1. POScroll to bottom of UITextView erratic in iOS 7
    primarykey
    data
    text
    <p>The following code will work fine in iOS &lt; 7.0. In iOS 7 the scrolling will be choppy and erratic while the UITextView is updating. I'm not sure if this is a bug in iOS 7, or I am doing something wrong. </p> <p><b>TestController.h</b></p> <pre><code>//TODO: Add UITextView in storyboard and tie to textView outlet #define MAX_TEXT_VIEW_CHARACTERS 1000 @interface TestController : UIViewController { NSMutableString *_outputText; NSTimer *_outputTimer; } @property (strong, nonatomic) IBOutlet UITextView *textView; @end </code></pre> <p><b>TestController.m</b></p> <pre><code>@implementation TestController @synthesize textView; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; _outputText = [NSMutableString stringWithCapacity:MAX_TEXT_VIEW_CHARACTERS]; _outputTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(outputLine:) userInfo:nil repeats:YES]; } -(void)outputLine:(NSTimer *) theTimer { static int i = 0; //Run this 100 times if (i &gt; 99) { [_outputTimer invalidate]; return; } [self outputToScreen:[NSString stringWithFormat:@"Some string %d\r", ++i]]; } -(void)outputToScreen:(NSString *)str { if (!str || !str.length) return; //Nothing to output NSInteger outputTextSize = _outputText.length; [_outputText appendString:str]; if (outputTextSize &gt; MAX_TEXT_VIEW_CHARACTERS) [_outputText deleteCharactersInRange:NSMakeRange(0, outputTextSize - MAX_TEXT_VIEW_CHARACTERS)]; self.textView.text = _outputText; [self scrollOutputToBottom]; } -(void)scrollOutputToBottom { CGPoint p = [textView contentOffset]; [textView setContentOffset:p animated:NO]; [textView scrollRangeToVisible:NSMakeRange([textView.text length], 0)]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload