tableView plain样式和group样式区别

来源:互联网 发布:advanced mac cleaner 编辑:程序博客网 时间:2024/05/17 09:26

Table views can have one of two styles, UITableViewStylePlain and UITableViewStyleGrouped. When you create a UITableView instance you must specify a table style, and this style cannot be changed. In the plain style, section headers and footers float above the content if the part of a complete section is visible. A table view can have an index that appears as a bar on the right hand side of the table (for example, "A" through "Z"). You can touch a particular label to jump to the target section. The grouped style of table view provides a default background color and a default background view for all cells. The background view provides a visual grouping for all cells in a particular section. For example, one group could be a person's name and title, another group for phone numbers that the person uses, and another group for email accounts and so on. See the Settings application for examples of grouped tables. Table views in the grouped style cannot have an index.

文档写的很详细,plain和group样式。一般而言,plain也就是我们常说的普通样式,在我看来,普通样式就是一个块(可以是一个或者多个分区)如下图这样:

普通视图主要用于动态表,而动态表一般在单元格数目未知的情况下使用

而分组样式呢,就是一个一个的块,特别分明的那种,就像文档中说的,一个组可以是人的名字和标题,另一个分区可以是这些人的电话号码,另一个分区可以是这些人的电子邮件等都可以,像下图这样:

分组样式一般用于静态表,用于界面布局,分组样式会把表分成很多“孤岛”,这些孤岛由一些类似的单元格组成。

了解了table的两种样式,以后根据需要来使用

分组样式也是可以用普通样式(基础样式)写出来的。

注意点:我们在定义table为分组样式时,他会有默认的分区高的,这个时候,我们如果不要这个分区高的话,应该return 0.01,不能是return 0;(return 0相当于是没有设置,是没有效果的)

如下图:我就是定义了一个静态样式来做的:

思路:静态样式表,"this is a label"是头视图。里边共用了两个分区,四类cell完成


1 0
原创粉丝点击