When to use UICollectionView instead of UITableView?

前端 未结 15 1669
闹比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: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.

提交回复
热议问题