Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert and remove a row from UITableView at the same time
    primarykey
    data
    text
    <p>I want to make a UITableView act like an accordion. When a row is tapped it should insert a special row right below the tapped row and then remove any other special row from previous taps. I have tried many things but the code below is my latest attempt.</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSIndexPath *removeIndex; for (int i = 0; i &lt; [players count]; i++) { NSString *player = [players objectAtIndex:i]; if ([player isEqualToString:@"ADJUST_SCORE_ROW"]) { removeIndex = [NSIndexPath indexPathForRow:i inSection:indexPath.section]; [players replaceObjectAtIndex:i withObject:@"DELETE_ME"]; break; } } [scoreTableView beginUpdates]; NSIndexPath *insertPath; if (removeIndex &amp;&amp; [removeIndex row] &lt; indexPath.row) { insertPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]; } else { insertPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; } [players insertObject:@"ADJUST_SCORE_ROW" atIndex:insertPath.row]; [scoreTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertPath] withRowAnimation:UITableViewRowAnimationTop]; for (int i = 0; i &lt; [players count]; i++) { NSString *player = [players objectAtIndex:i]; if ([player isEqualToString:@"DELETE_ME"]) { [players removeObject:player]; break; } } if (removeIndex) { [scoreTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:removeIndex] withRowAnimation:UITableViewRowAnimationTop]; } [scoreTableView endUpdates]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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