When to use UICollectionView instead of UITableView?

前端 未结 15 1599
闹比i
闹比i 2020-12-07 12:57

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

相关标签:
15条回答
  • 2020-12-07 13:42

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

    TABLEVIEW --> show list of items in only one column.

    COLLECTION-VIEW -->show list of items in multiple column.

    Hope it will help you.

    0 讨论(0)
  • 2020-12-07 13:44

    From my personal experience the two elements should only be compared loosly.

    TableView

    A TableView is a UI element designed for showing data in a list format. There is certain functionality that comes as standard with a UITableView, such as:

    • Accessory View
    • Cell Selection Style
    • Editting Style (Delete and edit buttons).

    The above elements enhance the usability of data when displaying and interacting in a list format. Such as viewing emails.

    CollectionView

    A CollectionView is a UI element designed for showing content using a custom layout (usually anything that isn't a list). CollectionViews improve functionality of displaying data in completely bespoke layout styles and also dynamically changing layouts on the fly. Some examples are:

    • Horizonal Lists
    • Photo Galleries
    • Thumbnail views
    • Carousels
    • Dials
    • Laying out elements on a map
    • etc.

    CollectionViews also allow for multiple selections.

    Conclusion

    As you can see from the above, both have completely different use cases and are designed for enhancing the development and usability of their own specific data sets.

    If you are looking at displaying anything in a list style with the followin interactions: - Adding - Deleting - Re-ordering Then a UITableView will simplify this process by providing the support straight out of the box.

    Anything else, you should leverage the benefits of CollectionView as you have more flexibility.

    0 讨论(0)
  • 2020-12-07 13:44

    I had this issue in my current project. Which to use. In my case it was simple really. I needed both. I needed my view to look like UITableView and also to change its change / layout. So, UICollectionView was used. I also use UITableView everywhere I don't need any extra customisation. Since UiTableView comes with a default layout that includes images and text - I use it for simplicity.

    0 讨论(0)
  • 2020-12-07 13:44

    Based on our requirement we choose UITableView or UICollection view.

    If we want to display images or items in grid type or if we need more customisability we use UICollectionview.

    For listing each item with details and subdetails we use UITableView.

    UICollectionView: 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.

    UITableView: 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.

    0 讨论(0)
  • 2020-12-07 13:46

    If you choose UITableView for iPhone, make sure you have considered your iPad strategy first. If you want an iPad-specific layout, you may want that single-column layout to become a grid.

    0 讨论(0)
  • In practice, everyone uses UICollectionView that I've come across, when they only need a UITableView. "It's one-dimensional. It goes up and down. Why are you adding unnecessary delegate methods for layout AND data?". I once spent an extra 2 hours helping a startup find out why their UICollectionViewCell got squished because the owner, who didn't read the Animations manual, nor HIG, nor the UICollectionView guide, decided to use it and add variable heights and anims. Needless to say, he gave himself a headache and much lost time on a non-business-critical issue he could have avoided by simply using a table cell, since there's no extra layout delegate + Nib.

    Let me get this straight, I am all for UICollectionView's when your data and display need it. They're very powerful. But in practice, most people I've seen have been using them on lists.

    This brings up another flaw. They're also used on short, constant lists that won't change, ever. In this case, just make a Xib. Or write a custom view that stacks them. Why? Because you don't need the memory management for 5 sets of labels with a button or switch. If they might change, then yes, use a list. If you want physics, then UICollectionView works well with a some cool effects. But do you really need to add 5 delegate methods and a layout system for 5 labels that will never move?

    Also, I'm not forgetting that iOS has a native stacking view now too. I can never get it to deform how I want, even though I'm quite adept at the 2D and animation systems, so I never use the built-in one.

    All I'm saying is, define your requirements. Maybe you don't need either of these, if your UI isn't adding/removing items and refreshing itself. Or maybe you want to write a Card Game and throw them out virtually on a table, then use UICollectionView with a physics system for its layout guide.

    0 讨论(0)
提交回复
热议问题