ios学习笔记UITableViewCell重用时出现重影的解决方案

来源:互联网 发布:红蜘蛛 软件 编辑:程序博客网 时间:2024/06/06 15:35

在UITableView中进行cell 的重用时,偶尔会出现重影的现象

通常我们这样写:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        static NSString *stee = @"hello";    UITableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:stee];    if (cell == nil){        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:stee];        cell.accessoryType = UITableViewCellAccessoryNone;    }        //标题    TitleL=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 60, cell.contentView.frame.size.height)];    [cell.contentView addSubview:TitleL];    TitleL.text=@"xxx";}

出现重影之后我们可以这样写:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        static NSString *stee = @"hello";    UITableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:stee];    if (cell == nil)    {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:stee];        cell.accessoryType = UITableViewCellAccessoryNone;        //标题        TitleL=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 60, cell.contentView.frame.size.height)];        TitleL.tag=101;        [cell.contentView addSubview:TitleL];            }
    UILabel *titleL=(UILabel *)[cell.contentView viewWithTag:101];
    titleL.text=@"xxxx";
<span style="font-family: Arial, Helvetica, sans-serif;">}</span>
  

0 0
原创粉丝点击