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];}

相關文章
相關標籤/搜索