Table View Programming Guide for iOS

来源:互联网 发布:淘宝账号管理在哪 编辑:程序博客网 时间:2024/06/05 13:24
目录:
  • Table View Styles and Accessory View
  • Overview of the Table View API
  • Navigating a Data Hierarchy with Table Views
  • Creating and Configuring a Table View
  • A Closer Look at Table View Cells
  • Managing Selections
  • Inserting and Deleting Rows and Sections
  • Managing the reordering of rows




Table View Styles and Accessory View
Table View Style
  • Plain Style
  • Group Style


其实plain通常用于显示同类的一连贯数据,而Group更适合于用来显示不同类型的数据。
其中plain能有indicator,而group不能有。
Standard Style for Table View Cells

UITableView提供四种默认的Cell样式:
  • UITableViewCellStyleDefault
  • UITableViewCellStyleSubtitle 
  • UITableViewCellStyleValue1
  • UITableViewCellStyleValue2

UITableViewCellStyleDefault:


UITableViewCellStyleSubtitle :


UITableViewCellStyleValue1:


UITableViewCellStyleValue2:


Accessory Views

UITableCell提供三种默认的附件:




Overview of the Table View API
Table View
Table View Controller

UITableViewController自动集成了一个UITableView,所以若需求是一个连续的Table界面,可以直接使用它。
Data Source and Delegate
Extension to the NSIndexPath Class

UITableView通过category的方式扩展了NSIndePath,使其具备row & section属性来更好地定位TableView的item
Table View Cells



Navigating a Data Hierarchy with Table Views

UITableView一个最为通用的用法就是用来导航浏览一个具有层级关系的数据
Hierarchical Data Models and Table View
View Controller and Navigation-Based Apps
Design pattern for Navigation-Based Apps



Creating and Configuring a Table View
Basic of Table View Creation





A Closer Look at Table View Cells

UITableViewCell设计如下:

Cell有通用模式和编辑模式:
  • 通用模式
    只有content、accessory View两个部分,acessory通常仅用于显示指示图标,如checkmark。
  • 编辑模式
    有editing、content、recording三部分,其中editing部分通常用于批量处理,而reordering 部分现在除了可用于重新排序呢,还可以用于删除曹组。


UITabelViewCell提供四种默认的Cell样子,若以下四种不能满足,则需要自定义。




Managing Selections



Inserting and Deleting Rows and Sections

当Cell处于编辑模式,我们可以实现row与section的inset、delete、reorder,批处理四种效果。

以下为client触发编辑模式并进行删除或者插入操作的时序图(时序图的执行顺序是从上而下):

  • setEditing:animated = 让table view 进去或者取消编辑模式
  • tableView:canEditRowAt = 确认指定的行列是否可以进入编辑模式
  • tableView:editingStyleForRowAtIndexPath = 制定某行进行编辑模式,这时候editing control已经显示在界面上了
  • tableView:commitEditingStyle:forRowAtIndexPath ,虽然这是一个可选方法,但在需要实现删除或者插入的操作时必须实现,并且得根据情况调用以下方法:
    • deleteRowsAtIndexPaths:withRowAnimation:
    • insertRowsAtIndexPaths:withRowAnimation:
    • 调用完以上方法还需要同时更新数据模型。

Batch Insertion ,Deletion,and Reloading of rows and section





Managing the reordering of rows


当table view收到setEditing:animation: 消息就会发送相同的消息给相应的cell,然后就会触发以下流程:
  1. table view发送tableView:canMoveRowAtIndexPath给DataSource,执行特定的cell能够显示reordering control。
  2. 每当一个拖动cell行为完成,tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:这个delegate方法用于判读这个动作是否效果
  3. 若上面的方法判定有效,则调用dataSource方法,tableView:moveRowAtIndexPath:toIndexPath: 更新model。


0 0
原创粉丝点击