You are correct in writing code to remove all content from a cell subcategory. But you wrote it in the wrong place. UITableView dequeueReusableCellWithIdentifier will return you a cell after it is dequeueReusableCellWithIdentifier and initialized once. That way, the code you wrote to remove cell.contentView.subViews will never run, and you will get Overlapped views.
You can either fix this code in an else statement, but I do not prefer this. Why select and initialize all contentView every cell in a UITableView cell. Rather, I created UILabel once and gave it a tag to access it later. Like this:
UILabel *lblDate = nil; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; lblDate = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 215, 10)]; lblDate.textColor = [UIColor grayColor]; lblDate.font = [UIFont systemFontOfSize:10.0]; lblDate.tag = 1; [lblDate setBackgroundColor:[UIColor clearColor]]; [cell.contentView addSubview:lblDate]; } else {
Puneet sharma
source share