Advantages of UITableView over UIScrollView

Subhodip Banerjee
redbus India Blog
Published in
2 min readMay 30, 2020
Picture Credit goes to raywenderlich.com :)

In my experience, I have seen most of the time iOS developers use UIScrollView to make the view content scrollable, where UITableView can save their life easily.

What is UIScrollView?

UIScrollView is a subclass of UIView and uses UIScrollViewDelegate protocol as a weak variable inside the UIScrollView class, which makes content scrollable, vertically, and horizontally. Scrollview content is not structured.

What is UITableView?

It is a subclass of UIScrollview, which allows vertical scrolling only.

So, now coming to the point, Advantages of using UITableView instead of UIScrollView?

  1. Memory:-
  • UITableView keeps the memory footprint lower. why? It uses Deque[Which allows insert and delete at both end] the existing cell it’s available in the cache or creates new using the class or nib files previously registered.
  • Where for UIScrollview, you have to add views manually every-time and it stays in memory until you remove them, so if more views are getting added, which will not be reused and for that memory will be increased and when it takes too much memory it will get terminated by the system.

2. Smooth Scrolling:-

  • In UIScrollview, all views are added manually with the help of auto layout, so when users scroll the content operating system continuously calculates coordinates of the view and as if more views are present in the content of the scroll view, which can consume battery faster. As a result, it affects the smoother scrolling experience.
  • In UITableVIew, Scrolling will be smooth through cell reuse with the help of prepareForReuse() method.

3. More functionality:-

  • In UITableView, you can quickly reload, insert, delete, edit, drag, drop, and reorder the cells.
  • Whereas in UIScrollview, to achieve/develop those top functionalities will take lots of code.

4. Size Calculation of each View Content:-

  • In UIScrollview, you have to figure out the frame of each view, If you are developing via code then lots of boilerplate code you have to write to set all constraints.
  • In UITableView, it automatically calculates the size and position for each reusable views, so lesser code here.

The above 4 points are the major advantages of UITableView instead of UIScrollView when developing a scalable, reusable, and scrollable UI components. Please add if I have missed any major points and share your thoughts in the comments section.

Thanks for reading!

Picture Credit goes to raywenderlich.com :)

--

--