UITableView使用指南
?
本文轉載至?http://blog.csdn.net/yu0089/article/details/8227402
?
一、概述?
UITableView是iOS開發比不可少也是最重要的一個控件類。可以說任何一個做iOS開發的人都必須熟練使用和掌握它。本文主要就是提供一個學習使用TableView的指南。?
要說UITableView必須要介紹他的幾個親戚:UITableViewDelegate,UITableViewDataSource,UITableViewCell。其中前兩個是TableView遵守的兩個protocol(別告訴我你不知道啥叫protocol哦)。然后本文會再列出TableView最常用最重要的一些知識點。最后再介紹幾個參考例子。?
二、UITableView和它的親戚們?
1. UITableView?
參考:?
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
1) 初始化 UITableView對象?
– initWithFrame:style:? // 代碼生成方式,如果你在nib里加的tableview不需要使用這個方法?
2)配置TableView?
– dequeueReusableCellWithIdentifier: // 必須要實現的方法,與TableView同生同死?
? style? property // 有兩種 UITableViewStylePlain, UITableViewStyleGrouped,經常用?
– numberOfRowsInSection:? //一個section有多少行,經常用?
– numberOfSections? //一個TableView有多少個section,經常用?
? rowHeight? property // 行高,和tableView:heightForRowAtIndexPath:有性能上的區別?
? separatorStyle? property // cell之間的分割線?待確認?
? separatorColor? property // 同上?
? backgroundView? property // tableview的背景view, 這個背景view在所有cell, header views, footer views之后?
? tableHeaderView? property // tableview上方的一個headerView, 和delete里的section header不是一個概念?
? tableFooterView? property // tableview下方的一個footerview?
? sectionHeaderHeight? property // section Header的高度,?
? sectionFooterHeight? property // sectjion Footer的高度?
? sectionIndexMinimumDisplayRowCount? property //? 功能待確認? 參考例子:? TheElements?
3) 訪問Cells和Sections?
– cellForRowAtIndexPath: //根據IndexPath返回cell?
– indexPathForCell: //根據cell返回它的indexPath,和上面的方法互補?
– indexPathForRowAtPoint://根據一個幾何點返回indexPath,如果超過邊界返回nil?
– indexPathsForRowsInRect: //根據一個幾何的矩形返回矩形所覆蓋的行,返回是一個indexPath數組?
– visibleCells // 不清楚怎么用,待確認?
– indexPathsForVisibleRows //同上?
4) 滾動TableView?
– scrollToRowAtIndexPath:atScrollPosition:animated: // 滾動到指定位置?
– scrollToNearestSelectedRowAtScrollPosition:animated: // 同上?
5) 管理sections?
– indexPathForSelectedRow //返回選定行的indexPath,單行?
– indexPathsForSelectedRows //返回選定行的indexPath數組,多行?
– selectRowAtIndexPath:animated:scrollPosition: //根據indexPath選擇一行?
– deselectRowAtIndexPath:animated: //反選一行,有何用??
? allowsSelection? property //是否允許用戶選取一行?
? allowsMultipleSelection? property // 是否選取多行,缺省為NO. 可以試試YES后的效果,哈哈?
? allowsSelectionDuringEditing? property // 編輯模式時是否可選取一行?
? allowsMultipleSelectionDuringEditing? property // 編輯模式時可否選取多行?
6) 插入、刪除、移動行和sections?
– beginUpdates // 和endUpdates一起用,讓插入、刪除、選擇操作同時動畫,沒用過?
– endUpdates //?
– insertRowsAtIndexPaths:withRowAnimation: //根據indexPath數組插入行?
– deleteRowsAtIndexPaths:withRowAnimation: //根據indexPath數組刪除行?
– moveRowAtIndexPath:toIndexPath: //移動一行到另一行?
– insertSections:withRowAnimation: //插入sections?
– deleteSections:withRowAnimation: //刪除sections?
– moveSection:toSection: //移動section?
7) 管理和編輯cell?
? editing? property // YES進入編輯模式,tableview cell會出現插入、刪除、重排序的控件?
– setEditing:animated: //設置進入退出編輯模式?
8) 重新加載TableView?
– reloadData // 重建整個表,包括cells、header、footer,indexs?
– reloadRowsAtIndexPaths:withRowAnimation: // 改進,不用reload整個表?
– reloadSections:withRowAnimation: // 同上?
– reloadSectionIndexTitles // 同上?
9) 訪問TableView的畫圖區?
– rectForSection: // 返回指定section的矩形?
– rectForRowAtIndexPath: //返回indexPath指定行的矩形?
– rectForFooterInSection: // 返回section的footer矩形?
– rectForHeaderInSection: // 返回section的header矩形?
10) Registering Nib Objects for Cell Reuse?
– registerNib:forCellReuseIdentifier: //?
11) 管理委托和數據源 (重要)?
? dataSource? property // 通常會這么用: myTableView.delegate = self; self 為viewController?
? delegate? property // 通常會這么用:???? myTableView.dataSource = self; self 為viewController?
原文地址:http://blog.csdn.net/y041039/article/details/7351982
轉載于:https://www.cnblogs.com/Camier-myNiuer/p/3858609.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的UITableView使用指南的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces 450B. Jz
- 下一篇: cxf restful