原文地址http://blog.sina.com.cn/s/blog_49fce0df01014th5.html

staticNSString*identifier = @"CELLIDENTIFIER";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];  // 复用tableviewcell


if (cell == nil)

{

  //创建tableviewcell

cell = [[[RankingCategoryTableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier] autorelease];

…… // 重绘tableviewcell中的组件,即改变组件的状态


UITableViewCell复用性原理:

在执行- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath代理方法时会新建几个tableviewcell,有几个tableviewcell取决于tableview开始显示时可以显示几个tableviewcell,以后滑动tableview时,不会再新建

tableviewcell, 即不再申请内存空间,直接复用已经存在的tableviewcell,即直接重绘tableviewcell。


UITableViewCell滑动时产生cell重叠的问题:

产生tableviewcell重叠的问题时因为没有对cell进行重绘,即没有重绘tableviewcell的子视图组件,必须改变子视图 的显示状态。


关于UITableViewCell重绘有两种解决方法:

1)直接自定义一个UITableViewCell,然后通过组件的getter,setter方法设计组件的状态。

2)每次复用时先将UITableViewCell上的子视图释放掉;

for (UIView *tempView in cell.contentView)

{

  [tempView removeFromSuperview];

  ……