UITableView 預習

UITableView繼承于UIScrollView,可以滾動。UITableView的每條數(shù)據(jù)對應的單元格叫做Cell,是UITableView的1個對象,繼承于UIView。

UITableView可以分區(qū)顯示, 每一個分區(qū)稱為section,每一行稱為row, 編號都從0開始。

系統(tǒng)提供了一個專門的類來整合section和row,叫做NSIndexPath。

UITableView*tableView = [[UITableViewalloc]initWithFrame:self.view.boundsstyle:UITableViewStylePlain];

[self.viewaddSubview:tableView];

[tableView release];

UITableView顯示的相關(guān)屬性

rowHeight ? ? 行高

separatarStyle ? 分隔線樣式

separatarColor ?分隔線顏色

tableHeaderView ? UITableView的置頂視圖

tableFooterView ? ?UITableView置底視圖

1.首先,Controller需要實現(xiàn)兩個delegate,分別是UITableViewDelegate和UITableViewDataSource

2.UITableView對象的delegate需要設(shè)置為self.

3.實現(xiàn)這些delegate的一些方法

(1)-(NSInteger)numberOfSetctionsInTableView:(UITableView *)tableView;這個方法返回tableview有多少個section

(2)-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;這個方法返回對應的section有多少個元素,也就是多少行

(3)-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndePath:(NSIndexPath *)indexPath;這個方法返回制定的row的高度。

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;這個方法返回指定的section和header view的高度。

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIteger)section;這個方法返回指定的section和footer view的高度;

(4)-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath;

返回指定的row的cell.這個地方很多人說比較關(guān)鍵,一般如何制定各種個性化的cell元素。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容