The method is very simple:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Some things to note:
If you need to get the cell and height of the tableview immediately after reloadData, or you need to scroll the tableview, then it is possible that you will have problems executing the code directly after reloadData.
reloadDate does not wait for the tableview to be updated before returning, but returns immediately, then calculates the table height, obtains cell, etc.
If the data in the table is very large and not executed in a run loop cycle, then there will be problems with the operation of tableview view data.
Apple does not directly provide the reloadData API. If you want the program to delay the operation until the reloadData ends, you can use the following method:
Method 1:
[ reloadData]; [ layoutIfNeeded]; //Refresh completed
Method 2:
[ reloadData]; dispatch_async(dispatch_get_main_queue(), ^{ //Refresh completed});
reloadDate will be executed on the main queue, and dispatch_get_main_queue will wait for the opportunity and will not be executed until the main queue is idle.
Similar functions:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated; - (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated; - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;
When refreshing data using [tableView reloadData];, the above function cannot be used directly in the subsequent context. reload
The above is what the editor introduces to you. Scroll to the specified position of the UITableView in IOS. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!