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元素。