您的位置:首页 > 产品设计 > UI/UE

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

2015-12-29 15:12 501 查看
在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>

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息