1

I saw many answers in SO which describes how can I scroll UITableView to the specific position.

I use setContentOffset for scrolling to particular position.

I meet a weird issue. If my tableView is half scrolled then setContentOffset is working properly. But when I scroll to end of the tableView and then use setContentOffset, table view scrolls a little bit more.

My setContentOffset value is CGPoint(0,199).

[self.tableView setContentOffset:CGPointMake(0,199) animated:NO];

After reaching a bottom I use setContentOffset. Then I check the contentOffset of UITableView. and it is 169.

I am not able to figure it out what exactly the issue is.

Edit::

I am using the following code. When a button in the last cell is pressed:

- (void)userPressedSubmitButtonOnLastCell
{

[self updateData];
[self.tableView reloadData];
[self performSelector:@selector(scrollTableView) withObject:nil afterDelay:0.5];
}

- (void)scrollTableView
{
 [self.tableView setContentOffset:CGPointMake(0,199) animated:NO];
}
Rahul
  • 5,594
  • 7
  • 38
  • 92

1 Answers1

1

Why don't you use tableView scrollToRowAtIndexPath: or tableView scrollRectToVisible:(CGRect)? This will allow you to scroll to either specific row or rectangle. ContentOffset is more suitable for UIScrollView.

Amani Elsaed
  • 1,558
  • 2
  • 21
  • 36
  • In bottom of my table view(in last row) their is a `UIButton`. On click of that button I need to scroll table view at the top. I can't use `tableView scrollToRowAtIndexPath:` because I have a header (table view header) also. And I need to show some part of Header also. – Rahul Apr 11 '17 at 13:49
  • I thought your question was about scrolling to the bottom, not to the top? – koen Apr 11 '17 at 13:51
  • I think you can use 'tableView scrollRectToVisible:' and set rect y = 0, so that it will scroll to top of the table – Amani Elsaed Apr 11 '17 at 13:53