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 *)pic
I was a bit confused by some of the answers I found to this question due to incomplete explanations. From what I've gathered, there's two routes to accomplish what OP requested and they are as follows:
If animation isn't a requirement, I'd suggest reseting scroll position before data loads using one of the offset methods. The reason you should run offset before reloadData is that reloadData runs asynchronously. If you run offset after reload, your scroll position will probably be a few rows down from the top.
tableView.setContentOffset(.zero, animated: false)
tableView.reloadData()
If animation is a requirement, position your scroll to the top row after you run reloadData using scrollToRow. The reason scrollToRow works here is that it positions you at the top of the table, versus the offset method that positions you relative to data that has already loaded.
tableView.reloadData()
tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)