title: UITableViewCell expand and collapse
body: <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
   //case 1
   //The user is selecting the cell which is currently expanded
   //we want to minimize it back
   if(selectedIndex == indexPath.row)
   {
      selectedIndex = -1;
      [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  
      return;
  }
  
  //case 2 
  //First we check if a cell is already expanded.
  //If it is we want to minimize make sure it is reloaded to minimize it back
  if(selectedIndex &gt;= 0)
  {
      NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
      selectedIndex = indexPath.row;
      [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];        
  }
  
  
  //case 3
  //Finally set the selected index to the new selection and reload it to expand
  selectedIndex = indexPath.row;
  [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  
  }
  </code></pre>
  
  <p>Notice how case 1 and case 2 are related collpasing already expanded row where as case 3 is about expanding the unexpanded row.</p>
  
  <p>Both the expand and collapse use the same function of reloadRowsAtIndexPaths function.</p>
  
  <p><strong>The question for me is that a toggle button, when it's expanded, run that function again will collapse and when it's collapsed, it will expand??</strong></p>