UITableView

2016-09-18  本文已影响4人  Hevin_Chen

什么是UITableView

- 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView

- UITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳

如何展示数据

- UITableView需要一个数据源(dataSource)来显示数据

- UITableView会向数据源查询一共有多少行数据以及每一行显示什么数据等

- 没有设置数据源的UITableView只是个空壳

- 凡是遵守UITableViewDataSource协议的OC对象,都可以是UITableView的数据源

tableView展示数据的过程

- 调用数据源的下面方法得知一共有多少组数据

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

-调用数据源的下面方法得知每一组有多少行数据

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

- 调用数据源的下面方法得知每一行显示什么内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

tableView如何显示数据

     - 设置dataSource数据源

     - 数据源要遵守UITableViewDataSource协议

     - 数据源要实现协议中的某些方法

// 告诉tableView一共有多少组数据

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

// 告诉tableView第section组有多少行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

// 告诉tableView第indexPath行显示怎样的cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

//告诉tableView第section组的头部标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

// 告诉tableView第section组的尾部标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section  

上一篇 下一篇

猜你喜欢

热点阅读