在iOS程序中,UITableView得到了广泛的应用。本系列文章将逐步由浅入深的探索UITableView特性。
1.UITableView的类型:
属性:style
有两种类型:Plain和Grouped@property(nonatomic, readonly) UITableViewStyle style // style为readonly,初始化设置后,不能再改变初始化方法:typedef enum { UITableViewStylePlain, UITableViewStyleGrouped } UITableViewStyle;
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style1.1 UITableViewStylePlain类型简介
spain类型的表格,在屏幕上由上往下连续的展示列表内容。列表可以分为一个或多个组(section),每个section里可以有一个或多个行(row),表格的默认背景色为白色。每个section可以有header和footer,header和footer可以为自定义的View。当表格滚动时,header和footer是悬浮的(float).在表格的右侧,可以添加索引栏(index bar)。当点击索引栏时,表格会滚动到相应的位置。1.2 UITableViewStyleGrouped类型简介
grouped类型的表格,也可以分section,section中有多个row。与spain的不同是,表格明确的由section分开,section是独立的,表格滚动时,section的header和footer也跟着滚动,而不是悬浮。
2.NSIndexPath简介
UITableView、UITableViewDataSource、UITableViewDelegate的许多方法都使用NSIndexPath作为参数或者返回值。以此,iOS SDK中为类NSIndexPath添加了 UITableView分类(Category).
NSIndexPath(UITableView) 有两个参数section、row和一个类方法+ indexPathForRow:inSection:组成。
3.UITableViewDataSource
协议UITableViewDataSoource的方法提供了表格的内容信息。Configuring a Table View
– numberOfSectionsInTableView:- 表格的组数,不实现,默认为1. 可选
– tableView:numberOfRowsInSection:required method- 表格每个section中的行数。必需
– tableView:cellForRowAtIndexPath:required method
– sectionIndexTitlesForTableView:– tableView:sectionForSectionIndexTitle:atIndex:– tableView:titleForHeaderInSection:– tableView:titleForFooterInSection:Inserting or Deleting Table Rows
Reordering Table Rows

本文详细介绍了UITableView的两种类型:Plain和Grouped,并对NSIndexPath的作用进行了说明。此外还解释了UITableViewDataSource和UITableViewDelegate协议的主要职责。
1529

被折叠的 条评论
为什么被折叠?



