How to get a UITableview to go to the top of page on reload?

uitableview scroll position after reload
uitableview stop reload on scroll
uitableview scroll to top
uitableview scroll to bottom programmatically swift
reload uitableview with animation swift 4
uitableview reloaddata without animation
swift uitableview scroll to bottom
uitableview scroll to bottom after reloaddata

I am trying to get a UITableview to go to the top of the page when I reload the table data when I call the following from

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

// A bunch of code …

[TableView reloadData];
}

Along those same lines, I would also like to be able to go to a specific section when I reload the table data.

I tried placing the following, which seems applicable only to the row, before and after the reload, but nothing happens:

[TableView scrollToRowAtIndexPath:0 atScrollPosition:UITableViewScrollPositionTop  animated:YES];

Here's another way you could do it:

Objective-C

[tableView setContentOffset:CGPointZero animated:YES];

Swift 3

tableView.setContentOffset(.zero, animated: true)

Probably the easiest and most straight forward way to do it.

iphone, Here's another way you could do it: Objective-C [tableView setContentOffset:​CGPointZero animated:YES];. Swift 3 tableView.setContentOffset(.zero, animated​:  It adjusts offsets if the table shrinks as a result of the reload. The table view’s delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to begin Updates() and end Updates() .

After reading all of the answers here and elsewhere, I finally found a solution that works reliably and does not show the scrolling after the data is loaded. My answer is based on this post and my observation that you need a negative offset if you are using content insets:

func reloadAndScrollToTop() {
    tableView.reloadData()
    tableView.layoutIfNeeded()
    tableView.contentOffset = CGPoint(x: 0, y: -tableView.contentInset.top)
}

Uitableview scroll to top after reload swift, Uitableview scroll to top after reload swift. If you make reload data while tableView is not visible on the screen you can faced with wrong offset after table view  func reloadAndScrollToTop() { tableView.reloadData() tableView.layoutIfNeeded() tableView.contentOffset = CGPoint(x: 0, y: -tableView.contentInset.top) } If you scroll before reloading and the number of rows decreases, you can have some strange animating behavior.

This is working for me.

tableView.scrollToRow(at: IndexPath.init(row: 0, section: 0), at: .top, animated: true)

Reloading UITableView while Animating Scroll in iOS 11, For example, if a scroll animation gets triggered and two separate properties of your data get updates, the pendingData should have both of these changes. This​  Understanding Reload, Repaint, and Re-Layout for UITableView Leaning the Objective-C language isn’t that bad; the true hurdle in learning to develop for iPhone is in understanding the frameworks. UITableView and UITableViewController is a perfect example of how a developer, new to iPhone, can get lost in a quagmire of documentation.

To scroll to a specific section you need to specify the index path to it:

NSIndexPath *topPath = [NSIndexPath indexPathForRow:0 inSection:0];
[TableView scrollToRowAtIndexPath:topPath
                 atScrollPosition:UITableViewScrollPositionTop
                         animated:YES];

If you are uncertain about the number of rows in your tableView. Use the following:

NSIndexPath *topPath = [NSIndexPath indexPathForRow:NSNotFound inSection:0];
[TableView scrollToRowAtIndexPath:topPath
                 atScrollPosition:UITableViewScrollPositionTop
                         animated:YES];

TableView w. Dynamic Height scrolls when reload |Apple , Summary My UITableView with dynamic cell heights randomly scrolls when inserting new cells at the top. Please turn JavaScript back on and reload this page. inaccurate scrolling when I trigger reloadData() and scroll I have the following working implementation based on this stack overflow answer:. Hey Guies, Good News to all of you. Learn Different technologies free. Learn free iOS Development, Phonegap Development, DotNet Development by just watching this video tutorial. Recorded for

WITHOUT ANIMATION

I'm on iOS11, using a plain tableview style with sticky headers and somehow the only way I got this to work correctly to have the tableview really on top after a reload without any strange flickers/animation behaviours was to use these methods in this order where ALL of these are necessary:

[self.tableView setContentOffset:CGPointZero animated:NO];
[self.tableView reloadData];
[self.tableView layoutIfNeeded];
[self.tableView setContentOffset:CGPointZero animated:NO];

I'm serious that all of these are necessary, even though it seems the first line is not relevant at all. Oh yeah, also very important, do NOT use this:

self.tableView.contentOffset = CGPointZero;

You would think that it's the same as the "setContentOffset animated:FALSE" but apparently it's not! Apple treats this method differently and in my case this only worked when using the full method with animated:FALSE.

WITH ANIMATION

I also wanted to try this with a nice scrolling animation to the top. There the content offset methods seemed to still cause some strange animation behaviours. The only way I got this working with a nice animation after some trial and error were these methods in this exact order:

[self.tableView reloadData];
[self.tableView layoutIfNeeded];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:TRUE];

Warning, make sure you have at least 1 row before running the last line of code to avoid crashing :)

I hope this helps someone someday!

UITableView Infinite Scrolling Tutorial, Infinite scrolling allows users to load content continuously, Start by downloading the starter project using the Download Materials link at the top or bottom of this tutorial. If you want to learn more about this specific API, visit Usage of When you receive a new page from the API, you have to add it to your​  No, by far the best way to jump to the top or bottom of a Web page is by tapping your Home or End key, respectively. This works in Chrome, Firefox, and Internet Explorer (and probably every other

UITableview: The Essential Solution for Scrolling iOS Interfaces, In a table view, scrolling is smoother (if you get your UITableView code right). In a UITableView, you can quickly reload, insert, delete, and reorder rows. Table views reuse cells that go out of the screen to display new As in any other view, we pin our subviews to the top and both sides of the cell. It may look a bit more complex than you expected. The reason is simple. Since iOS 10, the UITableView and UICollectionView classes have a refreshControl property. You can add a refresh control to a table or collection view by assigning an instance of the UIRefreshControl class to this property.

Retain scroll position in tableview after changing datasource · Issue , After the user starts to scroll the tableview I check if he reaches the end if so I load the table view (the tableview is sized over the whole screen but I'm presenting the if user reaches the 15th record (still 5 more to show) I start to load additional Make a subclass of UITableView and override reloadData. Hi. I have a case where I need to reload the cells because the value of certain fields may change (price, mood, etc). I do not want to do a full reload and I want to keep the currently viewed cells in place - I just need to trigger the currently rendered cells to update/re-populate their view based on the latest and greatest values that are stored in the backing list - I already keep a

Scroll UITableView to bottom after cells finish layout (Chat log), I want the UITableView to automatically start at the bottom of the list of chat messages (as the are resized (since different chat messages have different sized UITableViewCells) and the chat cells are pushed down a bit. top (​suggested) I made this cool animated background for my login screen on my food-based app! When usability testing participants were asked to return to the top of the page, the majority weren’t aware of the browser and operating system built-in options to get back to the top of the page. While some websites have added links or images at the bottom of long pages to make it easier to people to go back to the top, it’s not something

Comments
  • Thanks. That go me to the top of the page, which was my immediate need.
  • Sometimes this should be executed after a delay like 0.1 seconds. e.g. DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: { tableView.setContentOffset(.zero, animated: false) })
  • This should be marked as correct answer because it honors any insets that were set before
  • A combination of this and changing tableView.estimatedRowHeight to the height of my top separator did the job for me.
  • tableView.layoutIfNeeded() helped me after 1-2 hours of struggling!
  • If you're going to use contentOffset you should run it before you reloadData as reloadData runs asynchronously, therefore reloadData probably won't complete before contentOffset completes so your offset won't be accurate
  • Tried this with several adjustments. Best I got was a result an offset of 0, -25 after setting it to zero. Curious. But the solution with scrollToRow works: tableView.scrollToRow(at: IndexPath.init(row: 0, section: 0), at: .top, animated: true) - with checking for row and section count > 0.
  • Best way if your number of items has changed before (with reloadData)
  • @RPallas also best way when you have contentInset, but you should be careful then your tableview might be empty, it would crash app.
  • You should probably make sure that row exists in the table, otherwise it'll throw an exception.
  • Thanks for this code. I already released my App, but I want to use this in my first update.
  • @CameronSpickert See the updated for that condition.
  • Works great with parallex header table view. Thank you!
  • Work well with dynamic cell
  • Thanks. I tried this and it worked fine, but I went with the example below.