UITableView实用详解

1、UITableView 1.数据展现的条件 1> UITableView的全部数据都是由数据源(dataSource)提供的,因此要想在UITableView展现数据,必须设置UITableView的dataSource数据源对象 2> 要想当UITableView的dataSource对象,必须遵照UITableViewDataSource协议,实现相应的数据源方法 3> 当UITableView想要展现数据的时候,就会给数据源发送消息(调用数据源方法),UITableView会根据方法返回值决定展现怎样的数据缓存

2.数据展现的过程 1> 先调用数据源的性能优化

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 得知一共有多少组

2> 而后调用数据源的性能

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 得知第section组一共有多少行

3> 而后调用数据源的优化

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 得知第indexPath.section组 第indexPath.row 行显示怎样的cell(显示什么内容)

3.常见数据源方法 1> 一共有多少组orm

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

2> 第section组一共有多少行对象

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

3> 第indexPath.section组 第indexPath.row行显示怎样的cell(显示什么内容)animation

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

4> 第section组显示怎样 的头部标题string

  • (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;

5> 第section组显示怎样的尾部标题it

  • (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

4.tableView刷新数据的方式 1> 修改模型数据io

2> 刷新表格

  • reloadData 总体刷新(每一行都会刷新)
    • (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 局部刷新

5.性能优化 1> 定义一个循环利用标识 static NSString *ID = @"C1";

2> 从缓存池中取出可循环利用的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

3> 若是缓存池中没有可循环利用的cell if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; }

4> 覆盖cell上面的数据 cell.textLabel.text = [NSString stringWithFormat:@"第%d行数据", indexPath.row];

相关文章
相关标签/搜索