UITableView探索

来源:互联网 发布:阿里云 cdn 免费 编辑:程序博客网 时间:2024/04/29 12:29

在iOS程序中,UITableView得到了广泛的应用。本系列文章将逐步由浅入深的探索UITableView特性。

1.UITableView的类型:

属性:style  

@property(nonatomic, readonly) UITableViewStyle style   // style为readonly,初始化设置后,不能再改变
有两种类型:Plain和Grouped

typedef enum {   UITableViewStylePlain,         UITableViewStyleGrouped} UITableViewStyle;
初始化方法:
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style

1.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

  • – tableView:commitEditingStyle:forRowAtIndexPath:
  • – tableView:canEditRowAtIndexPath:

Reordering Table Rows

  • – tableView:canMoveRowAtIndexPath:
  • – tableView:moveRowAtIndexPath:toIndexPath:

4.UITableViewDelegate


原创粉丝点击