UITableView

UITableView是iOS系统中最重要的视图, 在常用的APP中随处可见。

UITableView

UITableView继承于UIScrollView,可以滚动。UITableView的每条数据对应的单元格叫做Cell,是UITableView的1个对象,继承于UIView。

UITableView可以分区显示, 每一个分区称为section,每一行称为row, 编号都从0开始。

系统提供了一个专门的类来整合section和row,叫做NSIndexPath。

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

[self.viewaddSubview:tableView];

[tableView release];

UITableView显示的相关属性

rowHeight     行高

separatarStyle   分隔线样式

separatarColor  分隔线颜色

tableHeaderView   UITableView的置顶视图

tableFooterView    UITableView置底视图


1.首先,Controller需要实现两个delegate,分别是UITableViewDelegate和UITableViewDataSource

2.UITableView对象的delegate需要设置为self.

3.实现这些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.这个地方很多人说比较关键,一般如何制定各种个性化的cell元素。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容