UIScrollView randomly scrolls when content is added

I have a view where some UITextViews are added to a UIScrollView. When the view appears, all the data is loaded correctly in scrollView, but I also have a tableView where you can select different taxes for the item. After selecting an element in this TableView, scrollView is again cleared and mounted with new elements. It fills scrollView with the correct data, but as soon as it fills, it arbitrarily moves to any scroll position instead of scrolling without animation at the top. I checked my code and after installing scrollView I use:

[self.scrollPreciosTarifasGUI scrollRectToVisible:CGRectZero animated:NO];

I also tried using:

[self.scrollPreciosTarifasGUI scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];

But I have the same result.

How can i fix this?

+5
source share
3 answers

I had a very similar problem with random scrolling and UITextViews. I really didn't find any solution, but by chance I put one scroll on another and it worked!

This is my code:

//newDetailViewController.view is uiscrollview type
[self.mainScrollView addSubview:newDetailViewController.view];
[newDetailViewController.view setFrame:CGRectMake(-2, 40, 800, 3300)];
+2
source

The solution hosted at http://opensourcehacker.com/2010/08/30/uiscrollview-setcontentoffset-random-scrolling-on-ios-4/ worked fine for me.

// Do it on iOS 4 or scrolls to a random position [scrollView setContentSize: CGSizeMake (0,0)];

// Update the view with new content [self updateContent: ...]

// We want the view to be displayed on top each time it is displayed [scrollView setContentOffset: CGPointMake (0,0) animated: NO];

// , . //contentHeight subviews. [scrollView setContentSize: CGSizeMake (self.view.frame.size.width, contentheight)];

+1

try this is just a wild guess

[self.scrollPreciosTarifasGUI scrollRectToVisible:CGRectMake(0,
                                                             0,
                                                             self.scrollPreciosTarifasGUI.frame.size.width,
                                                             self.scrollPreciosTarifasGUI.frame.size.height)
                              animated:NO];
0
source

All Articles