Should I use tableview, collectionview or scrollview when dealing with vertical items that are different from each other in the Xcode?

Asked

Viewed 95 times

0

Good night,

I started learning Swift a short time ago and am trying to develop an app in Xcode. Today I found the following situation: I need to make a list of information in which it is possible to scroll down, besides being able to expand vertically one of the lines of the list, sending the others down, so I thought: "Oh, a tableview, obviously...".

However, what happens is that all cells in this tableview will be totally different from each other, both in content and in the position of the elements within the cell. And taking into account all the examples of tableviews I’ve seen so far, it seems that they are always used for standardized lists, like the list of videos searched in the youtube app, for example. I started doing it by tableview and it seems to me that I’m doing a lot of atoa code, which should have an easier way of doing this kind of thing.

There, I discovered that there are two potential ways to do what I want: Collection views and scroll views, which in my ignorance seem to have a smaller focus on standardized lists.

So what I want to know is, which of these three solutions is best suited to my case, especially considering their ease and flexibility to deal with non-standard lists? Grateful.

1 answer

0


The Collection would not solve your problem, since it has the same usability, the difference between it and a Tableview basically is that, besides being able to have the horizontal scroll, it can contain columns. The table view can have its height modified to adapt to all types of content it needs using dynamic cells and its height being imposed by the use of constraints, where its code will be less coupled, creating a class for each type of cell. And in the latter case, you can use a Scrollview, but its use is limited compared to a Tableview, but you can structure the content completely randomly. Also another difference you need to worry about is features that a table has that a scrollview will not offer, such as selection, line deletion, among other features of each cell.



Use of Tableview with dynamic cells

TableView com células dinamicas


Use of Collectionview with 2 columns
ColectionView com 2 colunas

The example file is in this Github

  • Thank you so much for the very detailed answer! I ended up using a tableview even, solved well and was not as complicated as I thought. I’ll take a look at that file.

  • ATT: I took advantage of the project and I’m implementing a few more things but the idea remains the same

Browser other questions tagged

You are not signed in. Login or sign up in order to post.