How can I make scrolling NOT jump?
I have a simple test containing just an UITextView
in a UIViewController
created in a xib/ipad using XCode
Version 5.1.
The following code inserts 1000 rows and positions at the bottom.
When scrolling upwards by hand after a few hundred lines have been scrolled, the view jumps on its own to the bottom. As you continue scrolling up, it jumps again and again. You can see the row numbers reaching the 700 or 600 area and then back to the 900 area.
The problem does not always occur. You have to try several times. Seems to me it is more frequent when a small selection is done near the bottom, and even worse when the keyboard has been dismissed.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.textView.text = @"";
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i=0; i<1000; i++)
{
NSString *row = [NSString stringWithFormat:@"foo baz at line %d\n", i];
self.textView.text = [self.textView.text stringByAppendingString:row];
}
NSRange bottom = NSMakeRange(self.textView.text.length -1, 1);
[self.textView scrollRangeToVisible:bottom];
}