Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy subview of a UITableViewCell added incorrectly?
    text
    copied!<p>I have a problem. I implemented a table view. In <code>didSelectRowAtIndexPath</code> method I increase cell's height and add a textview to that cell's <code>contentView</code>. But if I scroll table view down(for 10 cells for example) I will see the same textview again. Can you please help me?</p> <p>here's some code for better understanding the problem:</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if(selectedIndex == indexPath.row) { return CELL_HEIGHT * 5; } return CELL_HEIGHT; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:TRUE]; UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; if (selectedIndex == indexPath.row) { selectedIndex = -1; [[cell.contentView viewWithTag:COOL_TAG] removeFromSuperview]; } else { UITableViewCell *previousCell = [aTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]]; if ([previousCell.contentView viewWithTag:COOL_TAG]) { [[previousCell.contentView viewWithTag:COOL_TAG] removeFromSuperview]; } selectedIndex = indexPath.row; UITextView *text = [[UITextView alloc] initWithFrame:CGRectMake(10, 45, 255, 180)]; [text.layer setBackgroundColor:[[UIColor whiteColor] CGColor]]; [text.layer setBorderColor:[[UIColor grayColor] CGColor]]; [text.layer setBorderWidth:1.0f]; [text.layer setCornerRadius: 8.0f]; [text.layer setMasksToBounds:YES]; [text setEditable:NO]; text.text = [questionArray objectAtIndex:indexPath.row]; text.tag = COOL_TAG; [cell.contentView addSubview:text]; } [tableView beginUpdates]; [tableView endUpdates]; } </code></pre> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload