在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>