When to use UICollectionView instead of UITableView?

I found that the UICollectionView is similar to the updated version of the UITableView introduced in iOS6, but when should I select the UICollectionView instead of the UITableView ?

There are applications using UITableView , if UICollectionView can do anything with UITableView , then why do people still use UITableView ? Is there a difference in performance?

Thank!

+69
ios objective-c uitableview uicollectionview
Apr 15 '14 at 8:52
source share
11 answers

It depends on the requirements. How application flows determine which type of user interface to integrate into the application.

Mostly users use UICollectionview to create types of user interfaces with multiple images displayed in a grid. This would have complicated logic with a UITableView , but with a UICollectionview it would be easy.

When using UICollectionview you don’t need to set buttons with tags or other things, getting the selected element 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 element, so it’s better to use UICollectionview to create a grid or changed elements.

People use a UITableView for listing information for each item because it displays more information about each item.

Apple Docs:

UICollectionView class reference

The UICollectionView class manages an ordered set of data items and presents them using custom layouts. Collection views provide the same general function as table views, except that the collection view can support more than single-column layouts. Collection views support custom layouts that you can use to implement multi-column grids, mosaic layouts, circular layouts, and more. You can even change the layout of the collection view dynamically if you want.

Link to the UITableView Class

The table view displays a list of items in a single column. UITableView is a subclass of UIScrollView that allows users to scroll through a table, although UITableView only allows vertical scrolling. Cells containing individual table elements are UITableViewCell objects; UITableView uses these objects to draw the visible rows of the table. Cells have content headers and images and can have accessory views near the right edge. Standard types of accessories are disclosure indicators or disclosure buttons; the former leads to the next level in the data hierarchy, and the latter leads to a detailed representation of the selected item. Accessory aspects can also be structure controls, such as switches and sliders, or can be customizable views. Table views can enter an editing mode in which users can insert, delete, and rearrange table rows.

+53
Apr 15 '14 at 9:02
source share

For simple lists and navigtaion forward / backward navigation, use UITableView .

If you need a high degree of customization, use the UICollectionView .

Generally speaking, when developing software, it's best to choose the approach that represents "The Simplest Possible Thing."

+24
Apr 15 '14 at 9:00
source share

Here are my criteria:

  • If a UITableView can do this, use it

  • If a UITableView needs a lot of code for this or cannot do it at all, use a UICollectionView.

You should consider the limitations on a UITableView before making a decision: this is a single column. And you can only customize cells, but not section backgrounds, etc. So, if you have the right list of things without unnecessary frills - this is similar to the standard iOS view for the swamp, basically - then use UITableview. If you have custom inserts or a border around each section, use a UICollectionView.

I really consider UICollectionView for all things simply because it is very expensive when you start developing your view as a table view and then find out that it cannot do what you need. First hand experience;)

Edit after even more experience with two: ignore this last paragraph. UICollectionView requires a lot of template code to work like a UITableView. Use UICollectionView only when it is really necessary .;)

+15
Aug 22 '16 at 11:51 on
source share

According to my point of view, the main difference between collectionView and tableView is that

TABLEVIEW β†’ show a list of items in only one column.

COLLECTION-VIEW β†’ show a list of items in multiple columns.

Hope this helps you.

+9
Apr 15 '15 at 16:09
source share

If you choose UITableView for iPhone, make sure you first review your iPad strategy. If you need a layout for your iPad, you might want the single-column layout to become a grid.

+8
Apr 07 '16 at 21:40
source share

Both depend on requirements. Table views also support many editing scenarios. This support was not implemented in Collection View classes. If you are moving from a table view that relies on these methods, expect to make a little extra heavy lifting in the collection. Collection View header headers can be placed anywhere in the view. and UITableView no need to set buttons with tags or other things, getting selected item values.

+4
Jun 18 '15 at 5:31 on
source share

Although not required, I always use the collection. That way, I can easily adapt how my collections are presented for different resolutions. The plus is that he is ready to quickly add new types of cells when refactoring in the future.

I do not see the point in table views. It is very simple to use a collection view to present a table. IMO.

+2
Dec 13 '16 at 22:17
source share

Its completely dependent on how your data is displayed. As mentioned above, if you only need one dataset and it is too complicated, go to UITableView else use UICollectionView .

UICollectionView convenient for customization.

If you're dealing with multiple cell heights or so, go to the UICollectionView .

+1
Apr 03 '17 at 6:51 on
source share

According to our need, we choose TableView or CollectionView.

Example:

For phone contacts, tableView is the best option.

For photo galleries, viewing the collection is the best option.

0
Apr 15 '14 at 9:01
source share

I had this problem in my current project. What to use. In my case, it was just really. I needed both. I needed my view to look like a UITableView, as well as change its change / layout. So, UICollectionView has been used. I also use UITableView wherever I need additional customization. Since UiTableView comes with a default layout that includes images and text - I use it for simplicity.

0
Apr 15 '14 at 9:50
source share

According to our requirement, we choose the UITableView or UICollection.

If we want to display images or elements in a grid type, or if we need additional customization, we use UICollectionview.

To list each item with details and subtasks, we use a UITableView.

UICollectionView: The UICollectionView class manages an ordered set of data items and presents them using custom layouts. Collection views provide the same general function as table views, except that the collection view can support more than single-column layouts.

UITableView: The table view displays a list of items in a single column. UITableView is a subclass of UIScrollView that allows users to scroll through a table, although a UITableView only allows vertical scrolling.

0
Oct 24 '16 at 14:13
source share



All Articles