Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView/UICollectionView scrolling looks choppy after Xcode 9.0 and iOS 11

I have four pages in the iPhone app. All 4 pages are subclass of UIViewController. Two pages have UITableView to show list of items. Two pages have UICollectionView to show data. All data fetched from web-service with help of AFNetworking. It comes very well without any issues. I show custom cells from storyboard for tableView and collectionView with all required and recommended methods.

It used to show smooth scrolling in simulator and devices before I updated my Xcode 8.3 to Xcode 9.0 and iOS 11. I tried with solutions from this and also other possible solutions from SO but does not solve my problem. Most confusing part is that I did not change single line of code for tableView or collectionView and it started showing choppy effect.

It looks like it waits for something every second and scrolling with noticeable pause even-though I do not have any complex logic while showing data. I just show data as it comes in web-service response. I have old branch as well which used to show smooth scrolling with Xcode 8.3 but when I run same code with Xcode 9.0, it show choppy scrolling.

I use macOS 10.12.6, Xcode 9, Swift 4 and simulators with iOS 11 and iOS 10.3.

like image 717
Vishal Gabani Avatar asked Oct 30 '17 07:10

Vishal Gabani


People also ask

What are uicollectionview and UITableView?

As most iOS developers know, displaying sets of data is a rather common task in building a mobile app. Apple’s SDK provides two components to help carry out such a task without having to implement everything from scratch: A table view ( UITableView) and a collection view ( UICollectionView).

Should I use a scroll view or a UITableView?

For example, many developers make their life harder using a scroll view when a UITableView would be a better choice. Finally, architecture is crucial for table views. The code of the table view data source often ends inside view controllers when it should go into a separate class.

What is the difference between the Settings app and UITableView?

For example, the Settings app uses tables and a navigation controller to organize the system settings. UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content.

What are table views in iOS?

Table views are a fundamental component of almost any iOS app. But most developers don’t use them when they should or get their architecture wrong. Table views are more versatile than you might think. For example, many developers make their life harder using a scroll view when a UITableView would be a better choice.


2 Answers

We found a workaround for this issue! If you simply implement

-[UITableView tableView:estimatedHeightForRowAtIndexPath:]

and return your

-[UITableView tableView:heightForRowAtIndexPath:]

everything will work.

Update: It turns out the core of the issue is that when you allocate a new UITableView with Xcode 8, the default value for UITableView.estimatedRowHeight is 0, whereas when you do the same with Xcode 9, the default value is -1, or UITableViewAutomaticDimension. Setting it back to 0 fixes the issue.

like image 91
bdmontz Avatar answered Nov 01 '22 22:11

bdmontz


Set isPrefetchingEnabled of your collection view to false, OR(which solves your problem way better) use pre-fetching methods in UICollectionViewDataSourcePrefetching/UITableViewDataSourcePrefetching to get smoother and more efficient scrolling. Make any web loading there for data to be ready for when a cell needs to be created

like image 32
Максуд Даудов Avatar answered Nov 01 '22 22:11

Максуд Даудов