Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView scrollToRow no longer works on iOS 11 right after adding a new row

I've noticed a weird UITableView behaviour which only seems to occur on iOS 11 devices.

Right after inserting a new row (changing data source and then calling reloadData, UITableView won't scroll to that row when calling scrollToRow or scrollToBottom() method.

When doing the some thing on iOS 10 or earlier version, it works perfectly and UITable scrolls like it's supposed to.

Thanks!

like image 916
Guy Avatar asked Sep 06 '17 12:09

Guy


1 Answers

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});

Adding a small delay is working in my case.

like image 126
Amos Hsueh Avatar answered Oct 14 '22 05:10

Amos Hsueh