Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use UICollectionView instead of UITableView?

I found that UICollectionView is like an upgraded version of UITableView introduced in iOS6, but when should I choose UICollectionView instead of UITableView?

There are still Apps using UITableView, if UICollectionView can do anything UITableView can do , why people still use UITableView? Is there a difference as far as performance is concerned?

Thanks!

like image 762
wz366 Avatar asked Apr 15 '14 08:04

wz366


People also ask

What is the difference between UICollectionView and UITableView?

UICollectionView is the model for displaying multidimensional data . UITableViewhas a couple of styles of cells stacked one over the other. You should not try to bend it to do any other kind of things too much complex than that kind of layout.

When would you choose to use a collection view rather than a table view?

Table view presents data in multiple rows arranged in a single column, the cell design is fit as a row. However, collection view can create rows and columns, it can design cells in various ways, even if they are not necessarily rows.

Will UITableView be deprecated?

It's already well known that UITableView class has become obsolete, and even Apple admits it. It's poorly customizable and has a variety of issues related to auto-resizing cells, autolayout, etc.

What is a UICollectionView?

An object that manages an ordered collection of data items and presents them using customizable layouts.


2 Answers

That depends on the requirements. How the application flows determines which type of UI to integrate into the application.

People mainly use the UICollectionview for creating types of UIs with multiple images shown in a grid. This would have complex logic using UITableView, but with UICollectionview, it would be easy.

When using UICollectionview, you don't need to set buttons with tags or other things by getting selected items values. You can simply get -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath and in UITableViewDelegate:

`-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath` 

You get the selected row instead of the item, so for creating grid or modified items, using UICollectionview is best.

For the listing details of each item, people use UITableView because it shows more info on each item.

Apple Docs:

UICollectionView Class Reference

The UICollectionView class manages an ordered collection of data items and presents them using customizable layouts. Collection views provide the same general function as table views except that a collection view is able to support more than just single-column layouts. Collection views support customizable layouts that can be used to implement multi-column grids, tiled layouts, circular layouts, and many more. You can even change the layout of a collection view dynamically if you want.

UITableView Class Reference

A table view displays a list of items in a single column. UITableView is a subclass of UIScrollView, which allows users to scroll through the table, although UITableView allows vertical scrolling only. The cells comprising the individual items of the table are UITableViewCell objects; UITableView uses these objects to draw the visible rows of the table. Cells have content—titles and images—and can have, near the right edge, accessory views. Standard accessory views are disclosure indicators or detail disclosure buttons; the former leads to the next level in a data hierarchy and the latter leads to a detailed view of a selected item. Accessory views can also be framework controls, such as switches and sliders, or can be custom views. Table views can enter an editing mode where users can insert, delete, and reorder rows of the table.

like image 120
Nitin Gohel Avatar answered Sep 18 '22 14:09

Nitin Gohel


Here's my criteria:

  • If a UITableView can do it, use it

  • If a UITableView needs lots of code to do it or can't do it at all, use UICollectionView.

You have to consider the restrictions on UITableView before making a decision: It's a single column. And you can only customize the cells, but not section backgrounds and such. So if you have a straight-up list of things with no extra frills - that looks like a bog standard iOS view, basically - then use UITableview. If you have custom insets, or a border around each section, use UICollectionView.

I'm actually considering UICollectionView for all things simply because it's very expensive when you start developing your view as a table view, then later find out it can't do that one thing that you need it to do. 1st hand experience ;)

Edit after even more experience with the two: Disregard that last paragraph. UICollectionView requires a lot of boilerplate code to make it work like a UITableView. Use UICollectionView only when really needed. ;)

like image 43
n13 Avatar answered Sep 20 '22 14:09

n13