Reputation: 353
I'm new to iOS development so this should probably be a easy question for someone. I am creating a scrollview (tried different ways, UIScrollView, UITableView, UITableViewController) and everytime i scroll down it scrolls back up to the top automatically. Why does this happen?
I understand "scrollsToTop" is listening for some guesture to scroll to top but that is set to NO so should not be that. "pagingEnabled" have been tested to be YES and NO but does not have an impact.
Tried to implement a UITableViewDelegate and override the scrollViewShouldSrollToTop function and return NO but the function is never called even though it is set as delegate of the tableView.
@interface Scroller : NSObject<UITableViewDelegate>
@implementation
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView )scrollView {return NO;}
// Did finish launching application
tableView = [[UITableView alloc] initWithFrame:tableRect style:UITableViewStyleGrouped];
self->tableView.pagingEnabled = NO;
tableView.scrollsToTop = NO;
[tableView setScrollsToTop:NO];
static Scroller s = [[Scroller alloc] init];
tableView.delegate = s;
Dont mind the formatting. It's all a mess. tableView belongs to the application delegate and is called in the ..didFinishLaunchingWithOptions:... function. I have a breakpoint in the Scroller function "scrollViewShouldScrollToTop" but it is never hit.
Upvotes: 4
Views: 9515
Reputation: 1653
You Should disable the bouncing property of scroll view set it to NO in Inrterface builder.
Upvotes: -1
Reputation: 353
I use UIScrollView instead of UITableView and set the contentSize to something bigger then the view frame and then it works. Still don't know what the problem with UITableView is though.
Upvotes: 1
Reputation: 5956
When there is not enough items to fill all height in UITableView
- it will scroll back every time.
Also you should set contentSize property for UIScrollView
to make it scrollable.
Scroll to top mentioned before should happened when user taps on status bar. But as i understand it's not your problem.
Upvotes: 0
Reputation: 73688
Auto scroll to top could happen maybe if you are tapping on the top bar (the black one)? In any case you can try to disable that feature -
[yourScrollView].scrollsToTop = NO;
this should apply to tableView
or scrollView
Upvotes: 6