iOS dynamically load new cell to the bottom of a t

2019-08-08 17:41发布

问题:

I'm working on an iOS project where I want to dynamically add more cell to the bottom of the tableview once the user reaches the bottom. I currently have this working by calling a method that fetches more data that is added to the array that I'm using to hold my cells. When I'm done adding the objects to the array I call [tableView reloadData]. This works, but it doesn't visually load the cell until the tableview stops scrolling.

I also tried using [tableView insertRowsAtIndexPaths: inSection:withRowAnimation: UITableViewRowAnimationNone]. But I was getting very strange behavior where random cell would disappear and not show back up until I scrolled that section of the tableView off screen and then back to that area.

Is there a way to get the tableView to reload even if the tableView is still in mid scroll when the [tableView reloadDate] is called?

Thank you!

回答1:

Check out: How to know when UITableView did scroll to bottom in iPhone neoneye's answer about - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { was exactly what I was looking for. I moved the method call to fetch more cell right after the NSLog(@"load more rows");

Thank you JiaYow for steering me in the right direction!