首页 > 系统 > iOS > 正文

Table View Programming Guide for iOS

2019-11-07 23:56:22
字体:
来源:转载
供稿:网友
目录:Table View Styles and accessory ViewOverview of the Table View APINavigating a Data Hierarchy with Table ViewsCreating and Configuring a Table ViewA Closer Look at Table View CellsManaging SelectionsInserting and Deleting Rows and SectionsManaging the reordering of rows
Table View Styles and Accessory View
Table View StylePlain StyleGroup Style其实plain通常用于显示同类的一连贯数据,而Group更适合于用来显示不同类型的数据。其中plain能有indicator,而group不能有。
Standard Style for Table View CellsUITableView提供四种默认的Cell样式:UITableViewCellStyleDefaultUITableViewCellStyleSubtitle UITableViewCellStyleValue1UITableViewCellStyleValue2UITableViewCellStyleDefault:UITableViewCellStyleSubtitle :UITableViewCellStyleValue1:UITableViewCellStyleValue2:
Accessory ViewsUITableCell提供三种默认的附件:

Overview of the Table View API
Table View
Table View ControllerUITableViewController自动集成了一个UITableView,所以若需求是一个连续的Table界面,可以直接使用它。
Data Source and Delegate
Extension to the NSIndexPath ClassUITableView通过category的方式扩展了NSIndePath,使其具备row & section属性来更好地定位TableView的item
Table View Cells

Navigating a Data Hierarchy with Table ViewsUITableView一个最为通用的用法就是用来导航浏览一个具有层级关系的数据
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 CellsUITableViewCell设计如下: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,然后就会触发以下流程:table view发送tableView:canMoveRowAtIndexPath给DataSource,执行特定的cell能够显示reordering control。每当一个拖动cell行为完成,tableView:targetIndexPathForMoveFromRowAtIndexPath:toPRoposedIndexPath:这个delegate方法用于判读这个动作是否效果若上面的方法判定有效,则调用dataSource方法,tableView:moveRowAtIndexPath:toIndexPath: 更新model。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表