UITableView,定制cell

UITableView,定制cell 内容 一、复习:缓存

设置表视图的行数,章节的个数对象

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

绘制cell (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathit

{UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@“cell"];io

cell.textLabel.text=_array[indexPath.row];table

单元格复用queue

定义复用cell的标识符,static NSString *reuse=@“cell”;方法

从复用队列里面获取cell对象,UITableViewCell *cell1=[tableView dequeueReusableCellWithIdentifier:reuse];static

若是cell对象不存在,从新建立cell if (cell1==nil)tab

{cell1=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];}

二、新内容:

利用绘制cell的方法去定制cell ( UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

static NSString *reuse = @“cell";

从缓存池中取出定制的cell

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];

if (cell == nil) {

实例化定制cell的对象 cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];}

相关文章
相关标签/搜索