Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. // disable touch on expanded cell
  4. UITableViewCell *cell = [self.theTableView cellForRowAtIndexPath:indexPath];
  5. if ([[cell reuseIdentifier] isEqualToString:@"ExpandedCellIdentifier"]) {
  6. return;
  7. }
  8.  
  9. // deselect row
  10. [tableView deselectRowAtIndexPath:indexPath
  11. animated:NO];
  12.  
  13. // get the actual index path
  14. indexPath = [self actualIndexPathForTappedIndexPath:indexPath];
  15.  
  16. // save the expanded cell to delete it later
  17. NSIndexPath *theExpandedIndexPath = self.expandedIndexPath;
  18.  
  19. // same row tapped twice - get rid of the expanded cell
  20. if ([indexPath isEqual:self.expandingIndexPath]) {
  21. self.expandingIndexPath = nil;
  22. self.expandedIndexPath = nil;
  23. }
  24. // add the expanded cell
  25. else {
  26. self.expandingIndexPath = indexPath;
  27. self.expandedIndexPath = [NSIndexPath indexPathForRow:[indexPath row] + 1
  28. inSection:[indexPath section]];
  29. }
  30.  
  31. [tableView beginUpdates];
  32.  
  33. if (theExpandedIndexPath) {
  34. [_theTableView deleteRowsAtIndexPaths:@[theExpandedIndexPath]
  35. withRowAnimation:UITableViewRowAnimationNone];
  36. }
  37. if (self.expandedIndexPath) {
  38. [_theTableView insertRowsAtIndexPaths:@[self.expandedIndexPath]
  39. withRowAnimation:UITableViewRowAnimationNone];
  40. }
  41.  
  42. [tableView endUpdates];
  43.  
  44. // scroll to the expanded cell
  45. [self.theTableView scrollToRowAtIndexPath:indexPath
  46. atScrollPosition:UITableViewScrollPositionMiddle
  47. animated:YES];
  48. }
  49.  
  50. - (IBAction)expand:(id)sender {
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement