何时使用 UICollectionView 而不是 UITableView? [英] When to use UICollectionView instead of UITableView?

查看:39
本文介绍了何时使用 UICollectionView 而不是 UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现UICollectionView就像是iOS6引入的UITableView的升级版,但是我什么时候应该选择UICollectionView而不是UITableView?

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

仍然有应用使用UITableView,如果UICollectionView 可以做任何UITableView 能做的事情,为什么人们还在使用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?

谢谢!

推荐答案

这取决于需求.应用程序的流动方式决定了将哪种类型的 UI 集成到应用程序中.

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

人们主要使用 UICollectionview 来创建在网格中显示多个图像的 UI 类型.使用 UITableView 会产生复杂的逻辑,但使用 UICollectionview 会很容易.

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.

使用 UICollectionview 时,您不需要通过获取选定项目的值来设置带有标签或其他东西的按钮.您可以简单地获取 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPathUITableViewDelegate:

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`

您获得的是选定的行而不是项目,因此对于创建网格或修改的项目,最好使用 UICollectionview.

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

对于每个项目的列表详细信息,人们使用 UITableView 因为它显示了每个项目的更多信息.

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

Apple 文档:

UICollectionView 类参考

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. 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 类参考

表格视图在单列中显示项目列表.UITableView 是 UIScrollView 的子类,它允许用户滚动表格,尽管 UITableView 只允许垂直滚动.组成表格各个项目的单元格是 UITableViewCell 对象;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. 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.

这篇关于何时使用 UICollectionView 而不是 UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆